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);
There is not much detail in the question, but if you are using a QDeclarativeView
to show the QML, have a look at its setResizeMode()
member. Setting this to QDeclarativeView::SizeRootObjectToView
might just do what you are looking for: it resizes QML's root object automatically to the size of the view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With