|
2012-06-16
, 15:56
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#2
|
... connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(changeLayout(int))); ... void MyWindow::changeLayout(int) { QRect screenGeometry = QApplication::desktop()->screenGeometry(int); if (screenGeometry.height() > screenGeometry.width()) { doPortraitLayout } else { restoreLandscapeLayout } }
The Following 4 Users Say Thank You to marxian For This Useful Post: | ||
|
2012-06-16
, 16:25
|
Posts: 3,328 |
Thanked: 4,476 times |
Joined on May 2011
@ Poland
|
#3
|
You need to handle the repositioning of the widgets manually by responding to the resized() signal of QDesktopWidget. You get the instance of QDesktopWidget by calling the static method QApplication::desktop().
e.g
Code:... connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(changeLayout(int))); ... void MyWindow::changeLayout(int) { QRect screenGeometry = QApplication::desktop()->screenGeometry(int); if (screenGeometry.height() > screenGeometry.width()) { doPortraitLayout } else { restoreLandscapeLayout } }
|
2012-06-16
, 17:05
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#4
|
And how should I do the portrait in Qt? I'm a beginner in Qt.
Could you show me some easy example of it? Will calling setupUi() be enough?
void MyWindow::portraitLayout() { ui->pushButton->setGeometry(100, 100, 200, 70); }
void MyWindow::landscapeLayout() { ui->pushButton->setGeometry(50, 50, 300, 70); }
The Following 3 Users Say Thank You to marxian For This Useful Post: | ||
|
2012-06-16
, 18:09
|
Posts: 3,328 |
Thanked: 4,476 times |
Joined on May 2011
@ Poland
|
#5
|
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:
and to restore the geometry:Code:void MyWindow::portraitLayout() { ui->pushButton->setGeometry(100, 100, 200, 70); }
If you are careful with the layouts, you shouldn't need to set the geometry/position of every widget individually.Code:void MyWindow::landscapeLayout() { ui->pushButton->setGeometry(50, 50, 300, 70); }
|
2012-06-16
, 18:51
|
|
Posts: 2,448 |
Thanked: 9,523 times |
Joined on Aug 2010
@ Wigan, UK
|
#6
|
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.
The Following User Says Thank You to marxian For This Useful Post: | ||
|
2012-06-17
, 06:09
|
Posts: 3,328 |
Thanked: 4,476 times |
Joined on May 2011
@ Poland
|
#7
|
The value were only suggestions, and you probably won't want to change the height of buttons, just perhaps the width. If you only need to change the position, and not the size, then it's better to use the move(int x, int y) method.
If you have a desktop target in addition to Maemo, you can easily test the portrait layout by adding a test method that sets the size of the window to 480 x 800 (maybe connect the method to the clicked() signal of one of the buttons). Just tinker with the values until you have a layout that you're happy with. Or test by deploying to the device and rotating. You can have a good guess at what the layout will look like from the values you choose, but the only way to be sure is to see what it looks like on screen.
void MyWindow::changeLayout(int) { QRect screenGeometry = QApplication::desktop()->screenGeometry(int); if (screenGeometry.height() > screenGeometry.width()) { //set QBoxLayout for portrait (created with the Designer?) } else { //set QBoxLayout for landscape } }
I was playing a bit around with Qt Designer.
1. I created some non 800x480 window. But it didn't occupy the whole window on device
2. I resized the window to 800x480. But then after rotation a huge part of the ui is cropped (as in stock mediaplayer with forced rotation)
What am I doing wrong? Or is qt designer unusable with Maemo? Or maybe it's just a bad style to use qt designer?
thanks in advance
If you want to support my work, you can donate by PayPal or Flattr
Projects no longer actively developed: here