Results 1 to 20 of 21

Thread: Issues with QGLWidget as QMainWindow central widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Issues with QGLWidget as QMainWindow central widget

    This code doesn't make sense:
    Qt Code:
    1. QSizePolicy sizeHint() {
    2. return QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    3. }
    To copy to clipboard, switch view to plain text mode 

    I don't know what you are trying to obtain with this, but sizeHint() returns QSize and not QSizePolicy and it's a const method too.

    See if it helps if you call update() at the end of resizeGL().
    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.


  2. #2
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Issues with QGLWidget as QMainWindow central widget

    Quote Originally Posted by wysota View Post
    I don't know what you are trying to obtain with this, but sizeHint() returns QSize and not QSizePolicy and it's a const method too.
    Oops! Thanks. That explains a few things. I changed the public methods to this:
    Qt Code:
    1. public:
    2. explicit ShardIRCClient(QWidget *parent = NULL);
    3.  
    4. QSize sizeHint() const {
    5. return QSize(800, 600);
    6. }
    7.  
    8. QSize minimumSizeHint() const {
    9. return QSize(640, 480);
    10. }
    To copy to clipboard, switch view to plain text mode 
    The window can now not be made smaller than a size to allow a 640*480 widget to fit, so that works properly. (QSizeHint::Preferred)


    Quote Originally Posted by wysota View Post
    See if it helps if you call update() at the end of resizeGL().
    Assuming you meant updateGL(): Yes and no. The widget now redraws when resizing it larger. It won't react if resized smaller and its overall performance is still oddly poor.

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

    Default Re: Issues with QGLWidget as QMainWindow central widget

    Quote Originally Posted by Zyl View Post
    Assuming you meant updateGL(): Yes and no.
    update() calls updateGL() so, no, I meant update()

    The widget now redraws when resizing it larger. It won't react if resized smaller and its overall performance is still oddly poor.
    Please provide a minimal compilable example reproducing the problem.
    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. #4
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Issues with QGLWidget as QMainWindow central widget

    This is the most minimal example I could make: Link
    Hope that shows what I mean.

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

    Default Re: Issues with QGLWidget as QMainWindow central widget

    I tested your app on Linux and I can't see any unexpected behaviour. When I resize the window (up or down), paintGL gets called.

    As for your note regarding updateGL()... Here is what paintEvent for QGLWidget looks like (which is what gets called upon calling update()):
    Qt Code:
    1. void QGLWidget::paintEvent(QPaintEvent *)
    2. {
    3. if (updatesEnabled()) {
    4. glDraw();
    5. updateOverlayGL();
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    and this is updateGL():

    Qt Code:
    1. void QGLWidget::updateGL()
    2. {
    3. if (updatesEnabled())
    4. glDraw();
    5. }
    To copy to clipboard, switch view to plain text mode 
    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.


  6. #6
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Issues with QGLWidget as QMainWindow central widget

    Strange. Using update() I get not additional paintGL()-calls, while with using updateGL() I do.
    Also I already do get automatic calls to paintGL() when resizing the window, without needing to set a call to update() nor updateGL(). However, although paintGL() is definitely called, there is no change visible unless I stop moving the mouse. Only an additional updateGL() call in resizeGL() causes a visible change, BUT ONLY when resizing the window larger. It really feels as if something's running on the wrong thread, and I don't see where I'd ever have to do with that. (Win7 x64 btw)

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

    Default Re: Issues with QGLWidget as QMainWindow central widget

    Unless you are using threads yourself, there is no threading involved. What you observe might be somehow caused by your system settings.
    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.


  8. #8
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Issues with QGLWidget as QMainWindow central widget

    I know of no system setting regarding the rendering mechanism of OpenGL in a window.

    If I remove this line from MainWindow::MainWindow
    Qt Code:
    1. this->setCentralWidget(widget);
    To copy to clipboard, switch view to plain text mode 
    the problem no longer occurs. However, no layouting is performed and the widget keeps its initial size.

    Doing layouting results in the whole problem returning however:
    Qt Code:
    1. #include <QHBoxLayout>
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent)
    5. {
    6. QWidget* center = new QWidget(this);
    7. QGLWidget* widget = new MyGLWidget(center);
    8. QHBoxLayout* layout = new QHBoxLayout(center);
    9. layout->setMargin(0);
    10. center->setLayout(layout);
    11. center->layout()->addWidget(widget);
    12. this->setCentralWidget(center);
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Zyl; 12th June 2012 at 00:39.

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

    Default Re: Issues with QGLWidget as QMainWindow central widget

    I didn't say the system setting has to be related to rendering of OpenGL in a window. You might have some system tweak installed that causes such behaviour. If what you observe was a common problem, it would have been identified and resolved a long time ago since it's quite common to use OpenGL child windows. Does it change anything if you call center->winId() (you can ignore the result) as part of your last code snippet?
    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. #10
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Issues with QGLWidget as QMainWindow central widget

    I don't think I have any outrageous system tweaks installed. The hackiest thing on this machine is probably Dropbox with its random folder scans.
    I tried adding center->winId() at various lines (and even multiple times), but there was no change.

    It might be worth working with the hint that just doing
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. QGLWidget* widget = new MyGLWidget(this);
    5. widget->setGeometry(0, 0, 800, 600);
    6. }
    To copy to clipboard, switch view to plain text mode 
    presents me the widget with proper performance. I can scale the window larger and as long as new parts of the 800*600 rectangle area of the widget are revealed paintGL() gets called and I see the redrawn content immediately, at what appears to be 60Hz - my screen's refresh rate; exactly what I want and one should expect. I can't help but think the problem to lie somewhere in the Qt layout classes.

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

    Default Re: Issues with QGLWidget as QMainWindow central widget

    Quote Originally Posted by Zyl View Post
    I don't think I have any outrageous system tweaks installed. The hackiest thing on this machine is probably Dropbox with its random folder scans.
    You'd be suprised how things tend to influence stuff logically unrelated to what the things are meant to do, especially when it comes to Windows.

    I tried adding center->winId() at various lines (and even multiple times), but there was no change.
    It was only needed once and in theory it shouldn't be needed at all

    I can't help but think the problem to lie somewhere in the Qt layout classes.
    Unlikely, especially since I've been using Qt+OpenGL+layouts and didn't experience any slowdowns.

    As an experiment, try this:

    Qt Code:
    1. class Widget : public QWidget {
    2. public:
    3. Widget(QWidget *parent = 0) : QWidget(parent) {
    4. w = new MyGLWidget(this);
    5. }
    6. protected:
    7. void resizeEvent(QResizeEvent *re) {
    8. w->setGeometry(0,0, width(), height());
    9. }
    10. MyGLWidget *w;
    11. };
    12.  
    13. int main(...) {
    14. ...
    15. Widget w;
    16. w.show();
    17. ...
    18. }
    To copy to clipboard, switch view to plain text mode 

    No layouts, same GL widget code. Is there a slowdown? If yes, what if you replace MyGLWidget with QGLWidget?
    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.


  12. #12
    Join Date
    Nov 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Issues with QGLWidget as QMainWindow central widget

    Same slow behaviour with MyGLWidget as well as with QGLWidget.
    If this goes on I'll try making a QThread spamming sizeInfo signals about the window size and catch them in a MyGLWidget slot... >_>
    EDIT: That actually works, but it acts equally crappy. (Yes I did just try it)
    Last edited by Zyl; 11th June 2012 at 23:35.

Similar Threads

  1. How can size of QMainWindow's central widget be managed?
    By yogeshm02 in forum Qt Programming
    Replies: 9
    Last Post: 28th March 2014, 21:12
  2. Replies: 2
    Last Post: 29th June 2011, 15:45
  3. Replies: 2
    Last Post: 7th June 2008, 13:12
  4. paint central widget of a QMainWindow???
    By Shuchi Agrawal in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 08:02
  5. Central Widget of QMainWindow
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 18:32

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
  •  
Qt is a trademark of The Qt Company.