Reply
Thread Tools
Posts: 3,328 | Thanked: 4,476 times | Joined on May 2011 @ Poland
#1
Hi
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
 
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#2
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
    }
}
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 

The Following 4 Users Say Thank You to marxian For This Useful Post:
Posts: 3,328 | Thanked: 4,476 times | Joined on May 2011 @ Poland
#3
Originally Posted by marxian View Post
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
    }
}
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?
__________________
If you want to support my work, you can donate by PayPal or Flattr

Projects no longer actively developed: here
 
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#4
Originally Posted by marmistrz View Post
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?
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.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 

The Following 3 Users Say Thank You to marxian For This Useful 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, 91 views)
__________________
If you want to support my work, you can donate by PayPal or Flattr

Projects no longer actively developed: here
 
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#6
Originally Posted by marmistrz View Post
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 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.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 

The Following User Says Thank You to marxian For This Useful Post:
Posts: 3,328 | Thanked: 4,476 times | Joined on May 2011 @ Poland
#7
Originally Posted by marxian View Post
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.
I've just though about something like that:
Code:
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 
    }
}
Is this approach worse? If yes, how much worse?
__________________
If you want to support my work, you can donate by PayPal or Flattr

Projects no longer actively developed: here
 
Reply


 
Forum Jump


All times are GMT. The time now is 12:57.