PDA

View Full Version : Extra moveEvent after calling winId for a widget.



Alex_123
23rd December 2008, 11:07
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.



#include <QApplication>
#include <QFrame>
#include <QDialog>
#include <QTabBar>
#include <QComboBox>
#include <QLabel>
#include <QtGui>
#include <Q3ListBox>
#include <QStyle>
#include <Qt3Support>
#include <QTabBar>
#include <QImage>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/extensions/shape.h>
#include <X11/Xatom.h>
#include <qx11info_x11.h>

class MyWidget : public QWidget
{
Q_OBJECT
public:
QFrame *m_frame;
QPushButton *btn;
MyWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) {};
~MyWidget() {delete btn;}
void moveEvent (QMoveEvent *e)
{
QRect g = geometry();
printf("Geometry is (%i, %i, %i, %i) %X\n", g.x(), g.y(), g.width(), g.height(), this);
}
protected:
void paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
}
};

int main(int argc, char *argv[])
{;
QApplication QApp(argc, argv);
MyWidget *W0 = new MyWidget(0, Qt::Window);
W0->winId();
W0->setGeometry(100, 200, 100, 200);
W0->show();
printf("%i, %i, %i, %i W0 = %X\n", W0->geometry().x(), W0->geometry().y(), W0->geometry().width(), W0->geometry().height(), W0);
return QApp.exec();
}
#include "main.moc"


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.

wysota
31st December 2008, 17:57
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.