Results 1 to 2 of 2

Thread: Extra moveEvent after calling winId for a widget.

  1. #1
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Extra moveEvent after calling winId for a widget.

    Hi. I have a question regarding Qt4 on X11. I'm wondering why do I get an extra move event with geometry (frameWidth, frameHeight) if I just call winId for a created widget before setting geometry. There's a code sample. Could anyone advice me how to avoid this? But I need to be able to have a winId before setGeometry.

    Qt Code:
    1. #include <QApplication>
    2. #include <QFrame>
    3. #include <QDialog>
    4. #include <QTabBar>
    5. #include <QComboBox>
    6. #include <QLabel>
    7. #include <QtGui>
    8. #include <Q3ListBox>
    9. #include <QStyle>
    10. #include <Qt3Support>
    11. #include <QTabBar>
    12. #include <QImage>
    13. #include <X11/X.h>
    14. #include <X11/Xlib.h>
    15. #include <X11/Xutil.h>
    16. #include <X11/Xresource.h>
    17. #include <X11/extensions/shape.h>
    18. #include <X11/Xatom.h>
    19. #include <qx11info_x11.h>
    20.  
    21. class MyWidget : public QWidget
    22. {
    23. Q_OBJECT
    24. public:
    25. QFrame *m_frame;
    26. MyWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) {};
    27. ~MyWidget() {delete btn;}
    28. void moveEvent (QMoveEvent *e)
    29. {
    30. QRect g = geometry();
    31. printf("Geometry is (%i, %i, %i, %i) %X\n", g.x(), g.y(), g.width(), g.height(), this);
    32. }
    33. protected:
    34. void paintEvent(QPaintEvent *e)
    35. {
    36. QWidget::paintEvent(e);
    37. }
    38. };
    39.  
    40. int main(int argc, char *argv[])
    41. {;
    42. QApplication QApp(argc, argv);
    43. MyWidget *W0 = new MyWidget(0, Qt::Window);
    44. W0->winId();
    45. W0->setGeometry(100, 200, 100, 200);
    46. W0->show();
    47. printf("%i, %i, %i, %i W0 = %X\n", W0->geometry().x(), W0->geometry().y(), W0->geometry().width(), W0->geometry().height(), W0);
    48. return QApp.exec();
    49. }
    50. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    So the output is following

    > Geometry is (100, 200, 100, 200) 8099C88
    > (100, 200, 100, 200) W0 = 8099C88
    > Geometry is (3, 21, 100, 200) 8099C88

    The latter one is from an extra moveEvent with wrong data, though the window remains positioned correctly while having wrong geometry. The QMoveEvent is spontaneous. 3, 21 are frameWidth and frameHeight obviously. Everything works fine if I call winId after setGeometry.
    Last edited by Alex_123; 23rd December 2008 at 11:59.

  2. #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: Extra moveEvent after calling winId for a widget.

    It's probably due to existance of "aliens". If you call winId() then Qt has to create a real widget for you at that moment. It might be forcing a move event but you can safely ignore it especially that all geometry is invalid before you show the widget for the first time.

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.