Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize QML widget embedded in QWidget?

Tags:

qt

qml

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);
like image 374
HammerSpb Avatar asked Feb 25 '23 19:02

HammerSpb


1 Answers

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.

like image 169
Steffen Avatar answered Feb 27 '23 08:02

Steffen