0

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.

UPDATE :

I have a QMainWindow with a QTableView as a widget, amongst others. When I expand the main Window, the tableview does not, and it leaves an ungainly blank space, so I fixed the size.

If I were to make it resizeable, how do I expand the QTableView widget, alongwith the QMainWindow. I have a Central Widget, this widget has a vertical box layout, and to this layout I've added the 3 widgets, one with QGridlayout, one horizontal line, and the other QTableView. The QTableView, on its own, is not inside a layout.

I'd imagined this would be sufficient to expand the table too, once QMainWindow were expanded, or reduced, but it doesn't happen.

How do i go about it, i.e., expanding the QTableView as well?

Thanks.

user1173240
  • 1,455
  • 2
  • 23
  • 50
  • http://stackoverflow.com/questions/8594969/get-physical-screen-size-in-qt should help you – vipw Feb 25 '13 at 09:35

1 Answers1

1

It will be a problem if you fix the size to one that is larger than the screen can handle. There are various ways to scale the size of a window according to the screen size. I recommend using QApplication::desktop(), which will return the desktop widget (you may need to #include <QDesktopWidget>. Note that this widget can actually encompass multiple screens, so if you just want the current screen, you can just do:

QRect screenGeometry = QApplication::desktop()->screenGeometry();

You could alternatively use QDesktopWidget::availableGeometry().

It is worth mentioning that among Qt users, I think there is a general dislike of fixed size windows. Most recommend taking full advantage of the Qt layout system, which provides lots of flexibility for resizing windows. I'm not saying you should definitely do this, because all projects are different, but it could be worth looking into.

Anthony
  • 8,570
  • 3
  • 38
  • 46
  • Thanks for your help. I'll certainly check it that way. I have a `QMainWindow` with a `QTableView` as a widget, amongst others. When I expand the main Window, the tableview does not, and it leaves an ungainly blank space, so I fixed the size. If I were to make it resizeable, how do I expand the `QTableView` widget, alongwith the `QMainWindow`, please? – user1173240 Feb 25 '13 at 17:10
  • Is your QTableView inside of a QLayout? – Anthony Feb 26 '13 at 00:48
  • No. Central Widget, this widget has a vertical box layout, and to this layout I've added the 3 widgets, one with `QGridlayout`, one horizontal line, and the other `QTableView`. The `QTableView`, on its own, is not inside a layout. Should I add a separate layout to `QTableView`, then? Which one should I add? – user1173240 Feb 26 '13 at 06:53
  • So you have a main window with a central widget, and the central widget has a vertical box layout with (1) another layout, (2), a horizontal line, and (3) the table view. That sounds right to me. You don't need to add the table view to another layout if it is already inside the QVBoxLayout. Something else must be wrong. Have you tried setting the table view's size policy to something like `MinimumExpanding`? – Anthony Feb 26 '13 at 11:23
  • Uh..huh...Deosn't work. `QMainWindow` has a central widget. Widget has a `VBoxLayout`. 3 widgets are added to this layout, one a widget have a `QGridLayout`, other a line,and third a `QTableView`. When I expand the Window, both the first widget ( with its own layout), and the line expand, but the `QTableView` does not. I have not set any special properties, size related, for the `QTableView`. What could possibly be the problem? – user1173240 Mar 05 '13 at 03:55
  • One last suggestion. Try this: `QSizePolicy policy = tableView->sizePolicy(); policy.setVerticalStretch(1); policy.setHorizontalStretch(1); tableView->setSizePolicy(policy);` – Anthony Mar 07 '13 at 11:12
  • Nope. That didn't work either. The table just won't expand, or reduce if I expand, or reduce, the `QMainWindow`. Always stays the same size, and doesn't budge. – user1173240 Mar 07 '13 at 12:05
  • Can you post the relevant code? There must be something wrong. It should probably be a separate question. – Anthony Mar 07 '13 at 12:25
  • Relevant code is in [link](http://stackoverflow.com/questions/15297182/qtableview-not-expanding-reducing-when-qmainwindow-is-resized) – user1173240 Mar 11 '13 at 03:10