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. QWindow inside a QQuickItem (QtDesktopComponents)
Forum Updated to NodeBB v4.3 + New Features

QWindow inside a QQuickItem (QtDesktopComponents)

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 5.8k 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.
  • A Offline
    A Offline
    anojan
    wrote on last edited by
    #1

    Hi,

    I'm trying to put a bunch of QWindow objects inside a SplitterRow component (QtDesktopComponent). And, I was wondering if it's possible to place a QWindow object (instantiated in C++) inside a QQuickItem?

    So far I tried reparenting like this, but it didn't work:
    @QQuickItem* item = qv->rootObject()->findChild<QQuickItem*>("test"); //qv is a QQuickView*
    mv->setParent((QWindow*)item); //mv is a QWindow*
    @

    Thanks.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      I am afraid this is not supported. A QWindow is not a QQuickItem and cannot be inserted as a child of one. But why do you want to put toplevel Windows inside a splitter?

      I am guessing perhaps you are trying to create a dockable window? Your best bet is to have an Item as a placeholder and create the Window dynamically when it is needed. You will probably run into difficulties though as it is not really a supported use case yet.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        anojan
        wrote on last edited by
        #3

        [quote author="Jens" date="1357157650"]I am afraid this is not supported. A QWindow is not a QQuickItem and cannot be inserted as a child of one. But why do you want to put toplevel Windows inside a splitter?
        [/quote]

        Thank you for the response Jens. I'm trying to put a QGLView inside the splitter if it's possible.

        [quote author="Jens" date="1357157650"]
        I am guessing perhaps you are trying to create a dockable window? Your best bet is to have an Item as a placeholder and create the Window dynamically when it is needed. You will probably run into difficulties though as it is not really a supported use case yet. [/quote]

        Well not really dockable. I'm just trying port my QWidget based program to QWindow and somehow lay them out with QtDesktopComponents.

        Thanks.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Martell Malone
          wrote on last edited by
          #4

          Hi Guid,

          This is exactly what I am trying to do.
          Could you tell me what route you went down?

          Many Thanks
          Martell

          1 Reply Last reply
          0
          • A Offline
            A Offline
            anojan
            wrote on last edited by
            #5

            Hi Martell,

            I ended up writing a QQuickPaintedItem wrapper for QGLView.

            @
            #ifndef QUICKMODELVIEW_H
            #define QUICKMODELVIEW_H

            #include <QQuickPaintedItem>
            #include "modelView.h"

            class quickModelView : public QQuickPaintedItem {
            Q_OBJECT
            Q_PROPERTY(QObject* modelView READ getModelView WRITE setModelView)
            public:
            quickModelView(QQuickItem* parent = 0);
            void paint(QPainter* painter);
            ModelView* getModelView();
            void setModelView(QObject* _mv);
            private:
            ModelView* mv; //ModelView inherits QGLView
            protected:
            void hoverMoveEvent(QHoverEvent *event);
            void mouseMoveEvent(QMouseEvent *event);
            void wheelEvent(QWheelEvent *event);
            void mousePressEvent(QMouseEvent *event);
            void mouseReleaseEvent(QMouseEvent *event);
            public slots:
            void resize();
            };

            #endif
            @

            @
            #include "qml/quickModelView.h"
            #include <QGLPainter>
            #include <QDebug>

            quickModelView::quickModelView(QQuickItem *parent) : QQuickPaintedItem(parent)
            {
            setFlag(QQuickItem::ItemHasContents, true);
            setRenderTarget(QQuickPaintedItem::InvertedYFramebufferObject);
            setAcceptHoverEvents(true);
            setAcceptedMouseButtons(Qt::AllButtons);
            // setKeepMouseGrab(true);
            setFillColor(QColor("#737373"));
            }

            void quickModelView::paint(QPainter* painter)
            {
            painter->beginNativePainting();
            QGLPainter glPainter(painter);

            if (!glPainter.begin(painter))
            {
            qDebug() << "GL graphics system is not active; cannot use 3D items";
            return;
            }
            else
            {
            glClear(GL_DEPTH_BUFFER_BIT);

            }

            if (glPainter.hasOpenGLFeature(QOpenGLFunctions::BlendColor))
            glPainter.glBlendColor(0, 0, 0, 0);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            if (glPainter.hasOpenGLFeature(QOpenGLFunctions::BlendEquation))
            glPainter.glBlendEquation(GL_FUNC_ADD);
            else if (glPainter.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate))
            glPainter.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);

            glPainter.clearAttributes();
            mv->render(&glPainter, height(), width());
            painter->endNativePainting();
            }

            ModelView *quickModelView::getModelView()
            {
            return mv;
            }

            void quickModelView::setModelView(QObject* _mv)
            {
            mv = qobject_cast<ModelView*>(_mv);
            connect(mv, SIGNAL(viewportChanged()), this, SLOT(update()));
            }

            void quickModelView::hoverMoveEvent(QHoverEvent *event)
            {
            mv->callMouseMoveEvent(event->pos(), height(), width());
            }

            void quickModelView::mouseMoveEvent(QMouseEvent *event)
            {
            mv->callMouseMoveEvent(event->pos(), height(), width());
            }

            void quickModelView::wheelEvent(QWheelEvent *event)
            {

            mv->callWheelEvent(event, QSize(width(),height()));
            }

            void quickModelView::mousePressEvent(QMouseEvent *event)
            {
            mv->callMousePressEvent(event);
            }

            void quickModelView::mouseReleaseEvent(QMouseEvent *event)
            {
            mv->callMouseReleaseEvent(event);
            }

            void quickModelView::resize()
            {
            setWidth(parentItem()->width());
            setHeight(parentItem()->height());
            }

            @

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Martell Malone
              wrote on last edited by
              #6

              Hi Guid,

              Thanks for the reply :)

              My problem is that the context must have certain settings as I am rendering the window from a game engine, specifically cocos2dx. I have to have 8 bits for the stencil buffer and 24 for the bit dept.

              So I manually set up an QOpenGLContext and set the surface as a QWindow.
              This worked perfectly.

              but when I try putting it in via QQuickPaintedItem and call all the opengl calls in paint I keep ending up with a gray screen.

              I think this is because the qwindow that the QQuickPaintedItem is in does not have the correct context stats?

              I've been at this for weeks.
              Even tried QSGMaterial method with no joy. :/

              I'll try to make a thread about having a desired QOpenGLContext for a qml window.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cvanegas
                wrote on last edited by
                #7

                Hi Guid,

                Thanks for posting your solution. I have a similar problem and was trying to follow your example. I was wondering if you could give us some more detail about your ModelView class that inherits QGLView. In particular, where does ModelView* mv get initialized and where are methods getModelView and setModelView called from.

                Thanks!

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  anojan
                  wrote on last edited by
                  #8

                  Hi,

                  There is nothing special about the ModelView class. It could be a generic QGLView.

                  main.cpp
                  @
                  #include "quickModelView.h" //the wrapper
                  #include "modelView.h" //the QGLView based class

                  //Register the wrapper for QML
                  qmlRegisterType<quickModelView>("gca", 1, 0, "QuickModelView");

                  //Instantiate a QGLView based object
                  ModelView *mv = new ModelView;

                  QQuickView *view = new QQuickView;
                  view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
                  view->rootContext()->setContextProperty("mv", mv); //pass mv to qml context
                  view->show();
                  @

                  myqmlfile.qml
                  @
                  import gca 1.0

                  QuickModelView{
                  width: 800;
                  height: 600;
                  modelView: mv; //This calls QuickModelView::setModelView(mv)
                  }
                  @

                  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