Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-28859

QWidgets renders badly in QGraphicsView, especially frame shapes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.0.0
    • Qt 4.8.x / Qt 5.0.0. Linux / Windows 7

    Description

      Widgets embedded in a QGraphicsView rendered by QGLWidget have wrong frame shapes. Some styles renders without any frame at all and some styles renders with wrong frame shape.

      Native style for Windows 7 have wrong frame shape of QListWidget and a lot of other widgets. Fusion style of Qt5 have missing frames and visible artifacts when focused. It's all very buggy and easy to find visual bugs. Focus on the frames because that's where most bugs are. QDoubleSpinbox flickers with black frame on Windows 7 with native style.

      I use this home made class to render my UI's using OpenGL:

      #ifndef QGLPARENT_H
      #define QGLPARENT_H
      
      #include <QGLWidget>
      #include <QGraphicsScene>
      #include <QGraphicsProxyWidget>
      #include <QGraphicsView>
      
      class QGLParent : public QGraphicsView
      {
      private:
      	QGraphicsProxyWidget *child;
      public:
      	QGLParent(QWidget *parent, QWidget *child) : QGraphicsView(parent)
      	{
      		setFrameShape(QFrame::NoFrame);
      		QGLFormat format(QGL::SampleBuffers);
      		format.setSwapInterval(1);
      
      		setScene(new QGraphicsScene());
                  	setViewport(new QGLWidget(format));
                  	//setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
      		
      		child->setWindowFlags(Qt::BypassGraphicsProxyWidget);
      		this->child = scene()->addWidget(child);
      	}
      protected:
      	void resizeEvent(QResizeEvent *event)
      	{
      		scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
      		child->resize(event->size().width(), event->size().height());
      		QGraphicsView::resizeEvent(event);
      	}
      };
      
      #endif
      

      Simply put any QWidget with child widgets in OpenGL like so:

      QGLParent glParent(0, any-root-widget-panel);
      glParent.show();

      You will find many graphical bugs this way.

      Here is one example using the QGLParent header:

      #include <QApplication>
      #include <QLineEdit>
      #include <QGLWidget>
      #include <QRect>
      
      #include <QSplitter>
      #include <QListWidget>
      #include <QtGui/QHBoxLayout>
      
      #include "QGLParent.h"
      
      #define USE_OPENGL 1
      
      int main(int argc, char **argv)
      {
      	QApplication app(argc, argv);
      
      	//One of the styles with bad rendering in OpenGL, Windows 7 style is another one
      	app.setStyle("fusion");
      
      	QWidget *Form = new QWidget;
      	QSplitter *splitter;
      	QListWidget *listWidget;
      	QLineEdit *widget;
      	QHBoxLayout *horizontalLayout;
      	horizontalLayout = new QHBoxLayout(Form);
              splitter = new QSplitter(Form);
              splitter->setOrientation(Qt::Horizontal);
              listWidget = new QListWidget(splitter);
              splitter->addWidget(listWidget);
              widget = new QLineEdit(splitter);
              splitter->addWidget(widget);
              horizontalLayout->addWidget(splitter);
      	
      #if USE_OPENGL
      	QGLParent glParent(0, Form);
      	glParent.show();
      #else
      	Form->show();
      #endif
      
      	return app.exec();
      }
      

      Set USE_OPENGL accordingly.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bachewii Jens
            alexhultman Alex Hultman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes