View Single Post
Posts: 3,328 | Thanked: 4,476 times | Joined on May 2011 @ Poland
#5
Originally Posted by marxian View Post
Calling setupUi() won't work because it won't have any code to take account of the screen geometry. You need to set the geometry or position of the widgets by calling the appropriate methods. You can access the widgets by calling ui->objectName (the objectNames can be set in Qt Designer), so if you have a QPushButton with objectName "pushButton", you can access it using ui->pushButton. Let's say this QPushbutton has x = 50, y = 50, width = 300, height = 70 when in landscape. To change the geometry to x = 100, y = 100, width = 200, height = 70 when in portrait, you would do:

Code:
void MyWindow::portraitLayout() {
    ui->pushButton->setGeometry(100, 100, 200, 70);
}
and to restore the geometry:

Code:
void MyWindow::landscapeLayout() {
    ui->pushButton->setGeometry(50, 50, 300, 70);
}
If you are careful with the layouts, you shouldn't need to set the geometry/position of every widget individually.
If a bit afraid of using the geometry as I'm not sure I lay it out perfectly. Or are these values only suggestions?

I'm attaching my .ui file. Will be setting the geometry of the most outer layout enough? Which ones' geometry would I need to change? I'm a bit confused with all that stuff.
Attached Files
File Type: gz mainwindow.ui.gz (681 Bytes, 94 views)
__________________
If you want to support my work, you can donate by PayPal or Flattr

Projects no longer actively developed: here