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. QtQuickItem with custom opengl draw - after first frame, item dissapear
Forum Updated to NodeBB v4.3 + New Features

QtQuickItem with custom opengl draw - after first frame, item dissapear

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 1 Posters 1.3k 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.
  • K Offline
    K Offline
    KrabQT
    wrote on last edited by
    #1

    Basically i have this simple window with one GridLayout (for simplicity i added just one column and two rows).
    In first row, i have GLViewer, which is QtQuickItem, that is drawing custom gl in beforeRendering slot ("inspired by this":http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html )
    When i run my app, all is ok, but when window is repainted (dragging or resizing, whatever causing repaint), my GLViewer dissapeared and i see ApplicationWindow background color instead (but paint method on GLViewer still called each repaint).

    @import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Layouts 1.1
    import ge.components 1.0

    ApplicationWindow {
    visible: true
    width: 1200
    height: 700
    title: qsTr("Hello World")
    color: "#292929"

    menuBar: MenuBar {
        Menu {
            title: qsTr("Filxe")
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
    
    GridLayout {
        columns: 1
        rows: 2
        anchors.fill: parent
    
        Rectangle {
            color: "white"
            Layout.row: 2
            Layout.column: 1
            Layout.fillWidth: true
            Layout.fillHeight: true
        }
    
        GLViewer {
            Layout.row: 1
            Layout.column: 1
            Layout.fillWidth: true
            Layout.fillHeight: true
        }
    
    }
    

    }@

    @#include "glviewer.h"
    #include <QQuickWindow>
    #include <iostream>
    #include <QColor>

    using namespace std;

    GLViewer::GLViewer(QQuickItem parent) :
    QQuickItem(parent)
    {
    connect(this, SIGNAL(windowChanged(QQuickWindow
    )), this, SLOT(handleWindowChanged(QQuickWindow*)));
    }

    void GLViewer::handleWindowChanged(QQuickWindow *win)
    {
    if (win) {
    connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
    win->setClearBeforeRendering(false);

    }
    

    }

    void GLViewer::paint() {

    QColor color = window()->color();
    glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    cout << "X: " << x() << ", Y: " << window()->height() - y() - height() << ", W: " << width() << ", H: " << height() << endl;
    
    glViewport(x(), window()->height() - y() - height(), width(), height());
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    QColor top(127, 145, 166), bottom(24, 26, 28);
    
    glBegin(GL_QUADS);
    glColor3f(bottom.redF(), bottom.greenF(), bottom.blueF());
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f(1.0f, -1.0f, 0.0f);
    glColor3f(top.redF(), top.greenF(), top.blueF());
    glVertex3f(1.0f, 1.0f, 0.0f);
    glVertex3f(-1.0f, 1.0f, 0.0f);
    glEnd();
    

    }
    @

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KrabQT
      wrote on last edited by
      #2

      first frame:
      !http://oi61.tinypic.com/2emzx9i.jpg(first frame)!

      second frame:
      !http://oi59.tinypic.com/2qv9x90.jpg(second frame)!

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KrabQT
        wrote on last edited by
        #3

        pleas Qt guys, does anyone know where is problem?

        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