Results 1 to 4 of 4

Thread: QDialog resizeEvent not happening in time?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default QDialog resizeEvent not happening in time?

    Hello,

    In trying to respond to a recent thread in this forum I wrote the following code:

    dialog.cpp
    Qt Code:
    1. #include "dialog.h"
    2. #include <QtGui>
    3. #include <QDebug>
    4.  
    5. Dialog::Dialog(QWidget *parent)
    6. : QDialog(parent)
    7. {
    8. scene = new QGraphicsScene();
    9. view = new QGraphicsView(scene, this);
    10. }
    11.  
    12. void Dialog::resizeEvent(QResizeEvent *e)
    13. {
    14. qDebug() << "Dialog::resizeEvent()" << e->size();
    15. view->resize(e->size());
    16. scene->setSceneRect(view->viewport()->rect());
    17. scene->clear();
    18. scene->addRect(0, 0, scene->sceneRect().width()-1, scene->sceneRect().height()-1);
    19. QDialog::resizeEvent(e);
    20. }
    To copy to clipboard, switch view to plain text mode 

    Adding a rectItem to the scene after it gets resized is simply to show myself that everything is sized as it should be. And this solution seems to work brilliantly if main.cpp looks like this:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "dialog.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Dialog w;
    8.  
    9. w.show();
    10. w.resize(500, 500);
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    With that code, I get the following debug output:

    Qt Code:
    1. Dialog::resizeEvent() QSize(131, 30)
    2. Dialog::resizeEvent() QSize(500, 500)
    To copy to clipboard, switch view to plain text mode 

    However, if the order of the method calls on w is reversed, I end up with only the following debug output:

    Qt Code:
    1. Dialog::resizeEvent() QSize(500, 500)
    To copy to clipboard, switch view to plain text mode 

    and get a small rectangle in the center of the dialog. Then, when I manually resize the window by even one pixel, the rectangle snaps into place and everything works from then on.

    Now, according to the documentation for QWidget::resize(),
    If the widget is visible when it is being resized, it receives a resize event (resizeEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.
    Based on what I see, I'm clearly not understanding what's going on here. That is, the event *is* being received but is not reflected in the output. Hopefully a good night's sleep will make all the pieces click but in the mean time I'm going crazy here. Can someone *please* try to explain why my little proof-rectangle apparently isn't being updated in time (or whatever this is)? Thanks a lot!
    Last edited by Urthas; 15th September 2010 at 05:47. Reason: added debug() output

Similar Threads

  1. resizeEvent help pls
    By munna in forum Newbie
    Replies: 10
    Last Post: 9th July 2010, 08:38
  2. toolbutton action is not happening.
    By phillip_Qt in forum Qt Programming
    Replies: 13
    Last Post: 19th November 2009, 09:13
  3. hook resizeEvent
    By prashant in forum Qt Programming
    Replies: 6
    Last Post: 7th September 2009, 11:35
  4. What cannot be done in resizeEvent(..)?
    By nifei in forum Qt Programming
    Replies: 2
    Last Post: 29th December 2008, 02:48
  5. Listbox Autoscroll is not happening?
    By mahe2310 in forum Qt Programming
    Replies: 4
    Last Post: 9th March 2006, 09:13

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.