QWindow inside a QQuickItem (QtDesktopComponents)



  • 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.



  • 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.



  • [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.



  • Hi Guid,

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

    Many Thanks
    Martell



  • 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());
    }

    @



  • 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.



  • 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!



  • 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)
    }
    @


Log in to reply
 

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