Need Help with QML/C++ resizing



  • Hello everybody,

    Using Qt4.8 I'm facing a problem in a QML/C++ project where the QML contents do not adjust when I resize the window despite calling setResizeMode with SizeRootObjectToView. A grey border will appear when I extend the window past its original resolution as shown in the first image in the following small album "HERE":http://imgur.com/a/dcj7N

    Next I tried implementing the resize event of the QWidget class. The event handler then generates a signal to explicitely tells the QML part to resize the top instance. It does resize the QML code, but the grey mask is still there and covers the interface, as shown in the second screenshot of the album.

    There are 15 green squares anchored to the right border of the top QML instance. Notice how they connect to the grey mask in the first case, and connect to the edge of the window behind the grey mask in the second!

    I'm kind of stumped, does anyone have suggestions on how I can solve this? Here's a choice cut from the top C++ object and QML class but I can provide more if it helps.

    @QmlContainer::QmlContainer(QWidget *parent) :
    QWidget(parent)
    {
    QSize qmlContainerSize(WINDOW_X, WINDOW_Y);
    //this->setFixedSize(qmlContainerSize);
    this->setMinimumSize(qmlContainerSize);

    viewer = new QmlApplicationViewer(this);
    viewer->addImportPath(QLatin1String("modules"));
    viewer->rootContext()->setContextProperty("mainWidget", this);
    viewer->rootContext()->setContextProperty("gammaBackend", gamma);
    viewer->rootContext()->setContextProperty("mainWidgetX", this->size().width());
    viewer->rootContext()->setContextProperty("mainWidgetY", this->size().height());
    viewer->engine()->addImageProvider(QLatin1String("pgrgraph"), graph);
    
    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
    viewer->setResizeMode(QmlApplicationViewer::SizeRootObjectToView);
    viewer->setMainQmlFile(QLatin1String("qml/sentryPgrViewer/main.qml"));
    viewer->showExpanded();
    }
    

    @

    @
    import QtQuick 1.1

    Rectangle {
    id: top
    color: "#FFD0FF"
    width: 1024
    height: 600

    Row {
        anchors.right: top.right
        spacing: 20
    
        Repeater {
            model: 15
    
            Rectangle { width: 20; height: 20; color: "green" }
        }
    }
    //For second example
    Connections {
            target: mainWidget;
            onSizeChanged: top.width = mainWidget.width
        }
    

    }//Top
    @

    Thank you very much!
    Leo



  • OK I found a solution.

    Encapsulating the QDecalarativeView object in a layout allows it to be resized. So:
    @QmlContainer::QmlContainer(QWidget *parent) :
    QWidget(parent)
    {
    QSize qmlContainerSize(WINDOW_X, WINDOW_Y);
    //this->setFixedSize(qmlContainerSize);
    this->setMinimumSize(qmlContainerSize);

    viewer = new QmlApplicationViewer(this);
    viewer->addImportPath(QLatin1String("modules"));
    viewer->rootContext()->setContextProperty("mainWidget", this);
    viewer->rootContext()->setContextProperty("gammaBackend", gamma);
    viewer->rootContext()->setContextProperty("mainWidgetX", this->size().width());
    viewer->rootContext()->setContextProperty("mainWidgetY", this->size().height());
    viewer->engine()->addImageProvider(QLatin1String("pgrgraph"), graph);
    
    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
    viewer->setResizeMode(QmlApplicationViewer::SizeRootObjectToView);
    viewer->setMainQmlFile(QLatin1String("qml/sentryPgrViewer/main.qml"));
    viewer->showExpanded();
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(viewer);
    setLayout(layout);
    }@
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.