How can i resize automatically QML widget?
I have QWidget created by hand.
In this widget created QML component.
But when i resize QWidget, QML component doesn't resize.
Some code…
I have MyCustomQWidget class
Header:
Class MyCustomQWidget : public QWidget
{
Q_OBJECT
public:
QDeclarativeView* view;
private:
QWidget* m_GUI;
public:
QWidget* getGUI() {return m_GUI;};
}
Source:
MyCustomQWidget:: MyCustomQWidget (QWidget *parent) :QWidget(parent)
{
m_GUI = new QWidget();
view = new QDeclarativeView(m_GUI);
view->setSource(QUrl("qrc:/qml/gui.qml"));
//view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
}
In main gui frame widget
QWidget* pCustomGUI = new MyCustomQWidget(…)
pVLayoutLeft->addWidget(pCustomGUI->getGUI);
Best Answer
There is not much detail in the question, but if you are using a
QDeclarativeView
to show the QML, have a look at itssetResizeMode()
member. Setting this toQDeclarativeView::SizeRootObjectToView
might just do what you are looking for: it resizes QML's root object automatically to the size of the view.