PDA

View Full Version : Problem with resize() on dual screen setup (X11/KDE)



TMan
24th February 2010, 15:53
Hey board,

I've got a problem with the QMainWindow::resize() function on a dual monitor setup. See the attached files to reproduce (if you have dual monitor setup of course!). The problem exists at least with Qt 4.6.0 on X11/KDE, but if I recall correctly I've seen it with older versions of Qt as well.

Anyway, what basically seems to happen is that resize() cannot set a size larger than one screen before the window is drawn. In the example if call resize(2400, 600) before calling app->exec(), the window will then be shown with a size of 1600x600 (because my monitor has 1600 pixels horizontally).

Then, I do a QTimer::singleShot of two seconds, and after these two seconds I call resize(2400,600) again. Now, the window has the desired size.

Does anyone have a suggestion on a proper fix for this problem? Thanks!


PS I had some problems with the attachments, so here are the sources (its not much anyway)

main.cpp:

#include <QtCore>
#include <QtGui>

#include "Test.h"

int main (int argc, char **argv)
{
QApplication app (argc, argv);

QMainWindow *w = new QMainWindow();
w->move (0,0);
w->resize(2400, 600);
w->show();

Test lT(w);
QTimer::singleShot (2000, &lT, SLOT(setSize()));

return app.exec();
}

Test.h:


#include <QtCore>
#include <QtGui>

class Test : public QObject
{
Q_OBJECT

public:
Test (QMainWindow *aMW)
{
mMW = aMW;
}

public slots:
void setSize ()
{
mMW->resize (2400, 600);
}

private:
QMainWindow *mMW;
};

TMan
25th February 2010, 08:46
I was hoping for some replies in the morning ... ;)

Anyway, I've been thinking, and I suppose it would help if I could get some signal when I'm sure that everything is drawn for the first time. I can then resize on that signal. However, looking at the QMainWindow documentation I see no such signal. Any suggestions?

TMan
25th February 2010, 10:28
For anyone having the same problem, it appears you can workaround this by calling qApp->processEvents() before qApp->exec() is called. Between these two calls you should now be able to resize. Obviously, this is a workaround and no real solution, so I'll submit a bugreport to Qt.