Results 1 to 7 of 7

Thread: QGLWidget doesn't hide

  1. #1
    Join Date
    Mar 2013
    Posts
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default QGLWidget doesn't hide

    Hello,

    I built an application for omap3530 device, based on (Qt 4.7 then Qt4.8) + Opengles.
    I followed this tutorial for SGX + Qt installation.

    The application consists in three main widgets: a QGLWidget used to display frames from a webcam, a QTableView used to display some execution events and a vertical QWidget with different QPushButton. One of them is used to switch between QGLWidget and QTableView.

    The application is able to switch once from QTableView to QGLWidget but when i get in that view, i can't hide the QGLWidget to display the QTableView. It seems that QGLWidget remains at the top of the screen, catching touch events, and that the main widget doesn't refresh the screen.

    I tried different solutions : put the three widget in a QHboxLayout and use hide/show slots, put QTableView and QGLWidget in a QStackedWidget, remove QGLWidget from the layout and set null size to QGLWidget (causes segfault) but none of these solutions works.

    Any ideas ?
    Thanks

  2. The following user says thank you to sebc06 for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGLWidget doesn't hide

    Show us some code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:


  5. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget doesn't hide

    Quote Originally Posted by sebc06 View Post
    The application consists in three main widgets: a QGLWidget used to display frames from a webcam, a QTableView used to display some execution events and a vertical QWidget with different QPushButton. One of them is used to switch between QGLWidget and QTableView.
    QWS is hopelessly buggy when it comes to mix widgets using a different paint engine in the same top level window. In fact the problem is completely unrelated to OpenGL beside, that an OpenGL widget uses a different paint engine, what introduces a subsurface.

    The reason why subsurfaces are always on top is because it is implemented this way. You can find the code in Qt that orders the subsurfaces always on top. You can change this implementation if you want to - but it won't take you far as there are many other issues left.

    I had commited a couple of patches for Qt 4.6 so that Qt/QWS is at least not broken when sub surfaces are enabled ( without using them ) - what happens as soon as you enable OpenGL when building Qt - and I have a couple of patches on my disk that I never committed as nobody in the development is interested to fix QWS anymore.

    But for your specific problem I recommend to implement an empty dummy widget that controls the position and visibility of the camera picture using the video4linux API. The image itself should be displayed on a higher hardware layer than the one where Qt is.

    Uwe

  6. The following user says thank you to Uwe for this useful post:


  7. #4
    Join Date
    Mar 2013
    Posts
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QGLWidget doesn't hide

    Thank you for your answer.
    Actually QGLWidget is also used to display some overlay data through QPainter, which can't be achieved through V4L (i think).

    Do you think your patches are compliant with Qt4.8 ??

    Here is a code sample to reproduce the error.

    Qt Code:
    1. class GLWidget : public QGLWidget {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6. GLWidget( );
    7.  
    8. protected:
    9. void paintGL();
    10. void initializeGL();
    11.  
    12. private:
    13. void genCross();
    14. QPixmap *crossPixmap;
    15. void drawCross(QPainter *painter);
    16.  
    17. QGLShaderProgram program;
    18. int matrixUniform;
    19. };
    20.  
    21. const QPainter::PixmapFragment crossCoord[4] = {
    22. QPainter::PixmapFragment::create(QPointF(300-15-8, 240), QRect(0, 0, 32, 4), 1, 1, 180, 1 ),
    23. QPainter::PixmapFragment::create(QPointF(300+15+8, 240), QRect(0, 0, 32, 4), 1, 1, 0, 1 ),
    24. QPainter::PixmapFragment::create(QPointF(300, 240-15-8), QRect(0, 0, 32, 4), 1, 1, -90, 1 ),
    25. QPainter::PixmapFragment::create(QPointF(300, 240+15+8), QRect(0, 0, 32, 4), 1, 1, 90, 1 )
    26. };
    27. const QPointF pts[5] = {
    28. QPointF(0, 0), QPointF(28, 0), QPointF(32, 2), QPointF(28, 4), QPointF(0, 4)};
    29.  
    30. GLWidget::GLWidget( )
    31. {
    32. genCross();
    33.  
    34. this->setAttribute(Qt::WA_AcceptTouchEvents);
    35. this->setAutoBufferSwap(false);
    36. this->setAttribute(Qt::WA_DeleteOnClose);
    37. this->setAutoFillBackground (false);
    38. }
    39.  
    40.  
    41. void GLWidget::initializeGL ()
    42. {
    43. QGLShader *vshader = new QGLShader(QGLShader::Vertex);
    44. const char *vsrc =
    45. "attribute highp vec4 vertex;\n"
    46. "attribute highp vec2 texCoord;\n"
    47. "uniform mediump mat4 matrix;\n"
    48. "varying highp vec2 texc;\n"
    49. "void main(void)\n"
    50. "{\n"
    51. " vec3 toLight = normalize(vec3(0.0, 0.3, 1.0));\n"
    52. " gl_Position = matrix * vertex;\n"
    53. " texc = texCoord;\n"
    54. "}\n";
    55. vshader->compileSourceCode(vsrc);
    56.  
    57. QGLShader *fshader = new QGLShader(QGLShader::Fragment);
    58. const char *fsrc =
    59. "varying highp vec2 texc;\n"
    60. "uniform sampler2D tex;\n"
    61. "void main(void)\n"
    62. "{\n"
    63. " highp vec3 color = texture2D(tex, texc.st).rgb;\n"
    64. " gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
    65. "}\n";
    66. fshader->compileSourceCode(fsrc);
    67.  
    68. program.addShader(vshader);
    69. program.addShader(fshader);
    70. program.link();
    71.  
    72. int vertexAttr = program.attributeLocation("vertex");
    73. int texCoordAttr = program.attributeLocation("texCoord");
    74. matrixUniform = program.uniformLocation("matrix");
    75. int textureUniform = program.uniformLocation("tex");
    76.  
    77. glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
    78. }
    79.  
    80. void GLWidget::paintGL()
    81. {
    82. QPainter livePainter(this);
    83.  
    84. livePainter.beginNativePainting();
    85.  
    86. glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
    87. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    88.  
    89. QMatrix4x4 modelview;
    90. modelview.translate(0, 0, 0);
    91. modelview.scale(1.0,1.0);
    92.  
    93. program.bind();
    94. program.setUniformValue(matrixUniform, modelview);
    95.  
    96. //gl stuff
    97. // ...
    98.  
    99. program.release();
    100.  
    101. livePainter.endNativePainting();
    102.  
    103. livePainter.drawPixmapFragments ( crossCoord, 4, *crossPixmap, QPainter::OpaqueHint );
    104.  
    105. livePainter.end();
    106.  
    107. swapBuffers();
    108.  
    109. }
    110.  
    111. void GLWidget::genCross()
    112. {
    113. crossPixmap = new QPixmap(32, 4);
    114.  
    115. QPen pen;
    116. pen.setBrush(Qt::black);
    117.  
    118. QPainter painter(crossPixmap);
    119.  
    120. painter.setBrush(Qt::yellow);
    121. painter.setPen(pen);
    122. painter.drawPolygon(pts, 5);
    123.  
    124. painter.end();
    125. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. class MainWindow : public QMainWindow
    4. {
    5. Q_OBJECT
    6. private slots:
    7. void toLog();
    8. void toLive();
    9.  
    10. public:
    11. MainWindow();
    12.  
    13. private:
    14. GLWidget *glwidget;
    15. QWidget *iEvent;
    16. };
    17.  
    18. MainWindow::MainWindow()
    19. {
    20. QWidget *centralWidget = new QWidget();
    21. this->setCentralWidget(centralWidget);
    22.  
    23. QGridLayout *mainLayout = new QGridLayout();
    24.  
    25. //Vertical menu
    26. QWidget *verticalMenu = new QWidget(centralWidget);
    27. verticalMenu->setFixedWidth(200);
    28. QVBoxLayout *layout = new QVBoxLayout();
    29. QPushButton *liveButton = new QPushButton("Live", verticalMenu);
    30. layout->addWidget(liveButton);
    31. QPushButton *logButton = new QPushButton("Log", verticalMenu);
    32. layout->addWidget(logButton);
    33. QPushButton *quitButton = new QPushButton("Quit", verticalMenu);
    34. layout->addWidget(quitButton);
    35. verticalMenu->setLayout(layout);
    36. mainLayout->addWidget(verticalMenu, 0, 2);
    37.  
    38. //Log view
    39. iEvent = new QWidget();
    40. QHBoxLayout *TableLayout = new QHBoxLayout();
    41. QTableView *tableView = new QTableView(this);
    42. model->setHeaderData(0, Qt::Horizontal, QObject::tr("Time"));
    43. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Source"));
    44. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Type"));
    45. model->setHeaderData(3, Qt::Horizontal, QObject::tr("Object"));
    46. tableView->setModel(model);
    47. TableLayout->addWidget(tableView);
    48. mainLayout->addWidget(iEvent, 0, 1);
    49. iEvent->setLayout(TableLayout);
    50.  
    51. //glWidget
    52. glwidget = new GLWidget();
    53. glwidget->hide();
    54. mainLayout->addWidget(glwidget, 0, 0);
    55.  
    56. QTimer *mainTimer = new QTimer();
    57. mainTimer->start(5);
    58. QObject::connect(mainTimer, SIGNAL(timeout()), glwidget, SLOT(updateGL()));
    59.  
    60. centralWidget->setLayout(mainLayout);
    61.  
    62. // Signals
    63. QObject::connect(logButton, SIGNAL(clicked()), this, SLOT(toLog()));
    64. QObject::connect(liveButton, SIGNAL(clicked()), this, SLOT(toLive()));
    65. QObject::connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    66. }
    67.  
    68. void MainWindow::toLog()
    69. {
    70. glwidget->hide();
    71. iEvent->show();
    72. }
    73. void MainWindow::toLive()
    74. {
    75. glwidget->show();
    76. iEvent->hide();
    77. }
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to sebc06 for this useful post:


  9. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGLWidget doesn't hide

    As far as the official line goes, QWS simply doesn't support OpenGL. If you're indeed using QWS then don't use OpenGL. If you need OpenGL, don't use QWS. Best if you just switch to Qt5 with wayland as the compositor. If your hardware supports OpenGLES, it should handle wayland as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:


  11. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget doesn't hide

    Quote Originally Posted by wysota View Post
    As far as the official line goes, QWS simply doesn't support OpenGL. If you're indeed using QWS then don't use OpenGL. If you need OpenGL, don't use QWS. Best if you just switch to Qt5 with wayland as the compositor. If your hardware supports OpenGLES, it should handle wayland as well.
    I'm not sure if this is really the official line - it's more like the current generation of Qt developers doesn't know QWS themself anymore. When I had to deal with these issues ( 4.6, 4.7 days ) the official line was, that QPA is the new thing and QWS won't be touched anymore. But QPA 4.8. was declared as "not worth to be documented yet" - so the situation is quite unsatisfying at the moment. Guess the strategy today is simply waiting for Wayland.

    But in fact QWS/OpenGL is not so far from being usable if someone would be interested in fixing it. F.e the wrong stacking order of the subsurfaces is an easy patch. More difficult is the logic that tries to restore parts of the screen from the backing store, that doesn't exits for OpenGL surfaces.

    So when you are not willing to patch Qt I would completely agree with Witold: QWS means raster only.

    Uwe

    Quote Originally Posted by wysota View Post
    As far as the official line goes, QWS simply doesn't support OpenGL. If you're indeed using QWS then don't use OpenGL. If you need OpenGL, don't use QWS. Best if you just switch to Qt5 with wayland as the compositor. If your hardware supports OpenGLES, it should handle wayland as well.
    I'm not sure if this is really the official line - it's more like the current generation of Qt developers doesn't know QWS themself anymore. When I had to deal with these issues ( 4.6, 4.7 days ) the official line was, that QPA is the new thing and QWS won't be touched anymore. But QPA 4.8. was declared as "not worth to be documented yet" - so the situation is quite unsatisfying at the moment. Guess the strategy today is simply waiting for Wayland.

    But in fact QWS/OpenGL is not so far from being usable if someone would be interested in fixing it. F.e the wrong stacking order of the subsurfaces is an easy patch. More difficult is the logic that tries to restore parts of the screen from the backing store, that doesn't exits for OpenGL surfaces.

    So when you are not willing to patch Qt I would completely agree with Witold: QWS means raster only.

    Uwe

    Quote Originally Posted by wysota View Post
    As far as the official line goes, QWS simply doesn't support OpenGL. If you're indeed using QWS then don't use OpenGL. If you need OpenGL, don't use QWS. Best if you just switch to Qt5 with wayland as the compositor. If your hardware supports OpenGLES, it should handle wayland as well.
    I'm not sure if this is really the official line - it's more like the current generation of Qt developers doesn't know QWS themself anymore. When I had to deal with these issues ( 4.6, 4.7 days ) the official line was, that QPA is the new thing and QWS won't be touched anymore. But QPA 4.8. was declared as "not worth to be documented yet" - so the situation is quite unsatisfying at the moment. Guess the strategy today is simply waiting for Wayland.

    But in fact QWS/OpenGL is not so far from being usable if someone would be interested in fixing it. F.e the wrong stacking order of the subsurfaces is an easy patch. More difficult is the logic that tries to restore parts of the screen from the backing store, that doesn't exits for OpenGL surfaces.

    So when you are not willing to patch Qt I would completely agree with Witold: QWS means raster only.

    Quote Originally Posted by sebc06 View Post
    Actually QGLWidget is also used to display some overlay data through QPainter, which can't be achieved through V4L (i think).
    Copying a camera image through QPainter/OpenGL is a complete waste of CPU. This could be done much better by hardware - if it supports stuff like different layers. I strongly recommend to read the specs of your GPU !

    Uwe
    Last edited by Uwe; 9th March 2013 at 09:44.

  12. The following user says thank you to Uwe for this useful post:


  13. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGLWidget doesn't hide

    Quote Originally Posted by Uwe View Post
    I'm not sure if this is really the official line - it's more like the current generation of Qt developers doesn't know QWS themself anymore. When I had to deal with these issues ( 4.6, 4.7 days ) the official line was, that QPA is the new thing and QWS won't be touched anymore. But QPA 4.8. was declared as "not worth to be documented yet" - so the situation is quite unsatisfying at the moment. Guess the strategy today is simply waiting for Wayland.
    One of the videos from last DevDays, the one on QPA in Qt5 contains a quote from the developer (AFAIR even with a slide to support that) that QWS doesn't support OpenGL. He also says it is technically possible to combine the two after a lot of struggle but it depends on the hardware and QWS simply isn't prepared for it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. The following user says thank you to wysota for this useful post:


Similar Threads

  1. One QGLWidget that manage QGLWidget childs
    By polch in forum Qt Programming
    Replies: 4
    Last Post: 12th December 2012, 11:26
  2. TrayIcon ContextMenu doesn't hide
    By krisztiantobias in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2012, 14:27
  3. QGLWidget doesn't update
    By qtbnl in forum Qt Programming
    Replies: 12
    Last Post: 14th February 2011, 17:41
  4. QGLWidget doesn't paint when I add another data member
    By Thoughtjacked in forum Qt Programming
    Replies: 6
    Last Post: 17th October 2007, 15:45
  5. Simple frame control doesn't resize when I hide()
    By MrGarbage in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2007, 22:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.