Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Problem with resizeEvent in QQuickView with SizeRootObjectToView on
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Problem with resizeEvent in QQuickView with SizeRootObjectToView on

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    matteli
    wrote on last edited by
    #1

    Hello all,

    To show the problem, here is a minimalist program :

    main.cpp
    @
    #include <QtGui/QGuiApplication>
    #include <QQuickView>

    class View : public QQuickView
    {
    public:
    View() {}
    };

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);
    View qv;
    qv.setSource(QUrl::fromLocalFile("qml/resize/main.qml"));
    qv.setWidth(300);
    qv.setHeight(500);
    qv.setResizeMode(QQuickView::SizeRootObjectToView);
    qv.show();
    return app.exec();
    }

    @

    main.qml
    @
    import QtQuick 2.0

    Item {
    id : root
    Rectangle {
    color: "red"
    anchors.fill: parent
    Text {
    text: "Height : " + root.height + " and width : " + root.width
    anchors.centerIn: parent
    }
    }
    }
    @

    Here, no problem. When i resize the windows, the red rectangle follows the window and the text show the size of the window.

    Now i'm introcing the resizeEvent.

    main.cpp
    @
    #include <QtGui/QGuiApplication>
    #include <QQuickView>

    class View : public QQuickView
    {
    public:
    View() {}
    protected:
    void resizeEvent(QResizeEvent * ev){}
    };

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);
    View qv;
    qv.setSource(QUrl::fromLocalFile("qml/resize/main.qml"));
    qv.setWidth(300);
    qv.setHeight(500);
    qv.setResizeMode(QQuickView::SizeRootObjectToView);
    qv.show();
    return app.exec();
    }

    @

    main.qml
    @
    import QtQuick 2.0

    Item {
    id : root
    Rectangle {
    color: "red"
    anchors.fill: parent
    Text {
    text: "Height : " + root.height + " and width : " + root.width
    anchors.centerIn: parent
    }
    }
    }
    @
    Here, the problem is that the size of the rectangle doe'nt change with the resizing.

    I'm looking in the source code of Qt 5.1 in the funtion that i have overload (resizeEvent), there nothing in the functions.

    So what ?

    Have i miss something ?
    Is thit a bug of Qt ?

    Thanks

    1 Reply Last reply
    0
    • M Offline
      M Offline
      matteli
      wrote on last edited by
      #2

      Ok i find a solution. If i put :
      @
      QQuickItem* rootQml = rootObject();
      rootQml->setProperty("width", ev->size().width());
      rootQml->setProperty("height", ev->size().height());
      @

      in the resizeEvent, it works.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved