PDA

View Full Version : QMainWindow resize problem



edb
9th January 2007, 16:09
Hi,

I have a problem with resizing QMainWindow. When I maximise or minimise the window, it sometimes happens that a part of the window falls outside the screen. In most cases, it happens when running the application on a laptop with a non-standard size screen. For example, when I maximise the screen using the maximise button and then minimise it, part of the window is not shown. For convenience I created a small demo application for this problem. This is the code:

QApplication a(argc,argv);
QMainWindow mwindow;
QSize size(3000,4000);
mwindow.setMaximumSize(size);
mwindow.show();
return a.exec();

I know the size I set is rediculously large, but It is just an example, it also happens with other values. As I don't know beforehand on which size of screen the program will run, I cannot hardcode the values. Can I load the maximumsize on startup based on the size of the screen? Any other suggestions?

Thanx!

ps: I use QT3 on Linux, but when I try it on windows, it also has the same problem.

wysota
9th January 2007, 21:51
How about using QWidget::showMaximized() instead of using such large values?

edb
11th January 2007, 11:27
Hi,
I tried that, but the problem still holds. It seems that it has to do something with a child widget that is larger dan the screen size en therefore enlarges the mainwindow. The child widget is a dockwindow and I dont't want this dockwindow to grow larger then the current mainwindowsize, ie, i don`t want my mainwindow resizing when I add a dockwindow. Kan I set the maximum size of a dockwindow to be the current mainwindowsize? I tried using QSizePolicy, but I don't see how to set the sizepolicy as setSizePolicy is a private member ....

Wish I could post the code of the dockwindow, but unfortunately I can't (copyright). Any tips on what can go wrong could help me in digging into the dockwindows code!

Thanx

wysota
11th January 2007, 14:57
So how come the dock widget is larger than the screen?

QWidget::setSizePolicy() a private member? Are you sure? I think it is enough to return a proper sizeHint() from the dockwidget. And if your widget may not fit on screen, consider putting it inside QScrollArea.

edb
12th January 2007, 08:07
Hi,

I tried setSizePolicy and overwriting sizeHint, but that didn't work. I kept getting inaccessibility errors on setSizePolicy. My compiler told me setSizePolicy is a private member, but when looking in QWidget.h it is public. This is the error I get:
" /usr/local/Trolltech/Qt-4.2.2/include/QtGui/qsizepolicy.h:148: error: 'QSizePolicy::QSizePolicy(int)' is private" I call setSizePolicy on a QMainWindow widget. It seems that the problem is in QSizePolicy and not in QMainWindow. At the moment I have no idea what's going wrong, but might this be a porting issue. We recently ported our QT3 code to QT4.

=> I looked in the header of QSizePolicy() and it seems that there is no public constructor which takes only one argument. I needed to set the size policy for both horizontal and vertical sizing. eg: myMainWindow->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Ma ximum);
myMainWindow->setSizePolicy(QSizePolicy::Maximum); thus doesn't work, altough I found void setSizePolicy(QSizePolicy) public in QWidget! QWidget also has a setSizePolicy which takes 2 arguments as the constructor of QSizePolicy. Could it be that void setSizePolicy(QSizePolicy ) is deprecated in QWidget???


Scrolling now works fine and for now, I can use the QScrollArea to solve the problem. However in the future I would like to redesign the widget so it can fit the screen without scrolling as this would be more convenient. If I find the problem and the solution while redesigning, I will add the solution to this post, but it might take some time.

Thanx for the help!

wysota
12th January 2007, 10:31
I tried setSizePolicy and overwriting sizeHint, but that didn't work. I kept getting inaccessibility errors on setSizePolicy. My compiler told me setSizePolicy is a private member, but when looking in QWidget.h it is public. This is the error I get:
" /usr/local/Trolltech/Qt-4.2.2/include/QtGui/qsizepolicy.h:148: error: 'QSizePolicy::QSizePolicy(int)' is private"
Read the error again - it doesn't say anything about setSizePolicy... You're just using a wrong constructor for QSizePolicy class.


I call setSizePolicy on a QMainWindow widget.
It won't work then. Size policies apply to widgets that are inside layouts. You have to set the policy for the dock widget's contents.

[quote]Could it be that void setSizePolicy(QSizePolicy ) is deprecated in QWidget???[/I]
No.