Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Resolution handling in QMainWindow
I've a QMainWwindow, and I've fixed its size.
i.e. I've set Minimum and maximum size of the window to the same number.
Could anyone tell me whether this will be a problem if I'm to use this in another screen with a different resolution, and if so, how am I to handle it?
Kindly advise, and also if there's another way ( perhaps more elegant) to set the size of the QMainWindow.
b1gsnak3 last edited by
Well... If you are using a fixed size you are generally using it with a purpose. One way to set a different size for different resolutions is to check for the desktop resolution and set a size according to the desktop. I.E. if the resolution is 1024x768 set the MW size to 400x300, and if the resolution is 1980x1024 set it to 600x500. This is just an example but you could do this if you really want to use a fixed size. A better way would be to use minimum and maximum size to offer a customization option for different users.
Size is in pixels, so it will stay the same on all screens. But, in the wake of high-DPI screens, it is possible that for some displays the pixels will be much smaller than on your test machine.
A solution would be to use widthMM() and heightMM() methods, which get the size in milimeters, or various *DPI methods that return pixel density. There is ongoing work in Qt (I think for both 4 and 5) to provide better support for retina screens, but I don't know current status.
Thanks for the information. I'll check on it.
I actually have a QMainWindow with multiple widgets, including a QTableView.
When the window is expanded, the tableview is not, and that leaves an ungainly blank space in the expanded area where there's no content, thus I fixed the Window size.
As I understand, it'd be beneficial to give the user a full experience of the Qt layout and customization experience...so in that case, how would I expand the QTableView automatically, alongwith the QMainWindow, once it is stretched? Is that possible, if so, how do I do it?
Any help would be appreciated, thanks.
This largely depends on your setup, but in general if you assign a widget to a QLayout, it will resize automatically. You also need to run setCentralWidget() in your QMainWindow (or use Designer and lay things out automatically).
It could happen that some other widget is actually resizing, taking up space away from your table view. You need to check your settings and pay attention to resizePolicy settings.
QMainWindow has 3 widgets, in a QVBoxLayout.
The first is a widget having many QLabels, in a GridLayout...
Second is a Horizontal line ( not to be worried)..
And the third is the QTableView.
All these are placed in a central widget of the QMainWindow.
Since I am new to Qt, this was the simplest thing I could come up with..I thought it'd expand automatically, albeit stretching the font and labels etc..but it doesn't. Just expands the Main Window, and the actual central widget stays put.
setCentralWidget() is your friend, then. Put it somewhere in the constructor and you should be fine. If that does not work, adjust GridLayout to sport a MinimalExpanding policy, and tableview to use Expanding one.
Thanks for your help. I'll check these options.