Author Topic: Appropriate resizing of QT dialogs and such  (Read 9943 times)

vanstrien

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • http://www.vanstrien.net
Appropriate resizing of QT dialogs and such
« on: November 11, 2004, 06:56:40 am »
Hope this isn't too much of a newbie QT question...

On all my dialog boxes based on QDialog, QMessageBox or QWidget I have a fairly consistent problem with incorrect resizing of the windows.  Essentially if I design a window Designer which looks just fine, when I then compile and run the app with the window for an 860 some of the text or other objects are obscured.  Essentially the window is not resizing/expanding in response to different size fonts, etc.

Of course if I resize the window in Designer to fit well to the 860, then it looks way too big on a 5500.  What am I missing to make the whole window automatically resize as needed?

I use vertica and horizontal layouts extensively.  I have also tried extra calls to resize() and have reimplemented it to handle some specific requirements.
C860 Cacko ROM | 5500 tkcROM
256MB SD | 128MB SD
512MB CF | 256MB CF
D-Link DWL 660 WiFi| Linksys WCF12 WiFi
Socket Bluetooth | Socket Ethernet

clivel

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
    • http://www.bundu.com
Appropriate resizing of QT dialogs and such
« Reply #1 on: November 11, 2004, 03:16:59 pm »
Hi,
I don't use Designer, instead I  position all the controls manually in the Dialog constructor. The postion and size of the controls is calculated according to the screen resolution. This is painful, but seems to provide the best way of ensuring that everything fits just how I like.
I am not a great fan of layouts, in my experience, they seem to often do an adequate but not very good job of creating a nice looking screen.
Regards,
Clive

ashikase

  • Sr. Member
  • ****
  • Posts: 280
    • View Profile
    • http://
Appropriate resizing of QT dialogs and such
« Reply #2 on: November 11, 2004, 06:19:18 pm »
Vanstrien:

It's hard to tell what the problem might be without seeing the code. If the generated GUI code is small enough you might try posting it here, or just provide a link to it.

One thing you might want to check, though... did you make sure to add a layout to the root dialog? In other words, when you select 'new' in QtDesigner, it gives you a blank root dialog to place your widgets in. Once you've laid out all your widgets, make sure to right-click on the root dialog and select a layout. Everything must be inside a layout for resizing to work properly.

- ashikase
  anpachi, gifu, japan
SL-C3100 & SL-C760

vanstrien

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • http://www.vanstrien.net
Appropriate resizing of QT dialogs and such
« Reply #3 on: November 11, 2004, 06:31:22 pm »
Thanks Ashikase.

I used to do my dialog development the same as you: writing the code rather than using Designer to setup a base class.  I just started using Designer as some of my interfaces became more complex (and so I could learn something new)

I do have some code that I can use as an example, but I will need to extract it into something worth looking at.  I appreciate your help and will repost something as soon as I can.
C860 Cacko ROM | 5500 tkcROM
256MB SD | 128MB SD
512MB CF | 256MB CF
D-Link DWL 660 WiFi| Linksys WCF12 WiFi
Socket Bluetooth | Socket Ethernet

ashikase

  • Sr. Member
  • ****
  • Posts: 280
    • View Profile
    • http://
Appropriate resizing of QT dialogs and such
« Reply #4 on: November 11, 2004, 09:18:53 pm »
vanstrien:

I think you misunderstood... I use QtDesigner as well. What I meant was that you should post the code that uic generates from the .ui file(s). Alternatively, you could just post the .ui file itself.

- ashikase
  anpachi, gifu, japan
SL-C3100 & SL-C760

vanstrien

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • http://www.vanstrien.net
Appropriate resizing of QT dialogs and such
« Reply #5 on: November 12, 2004, 07:23:41 am »
(ashikase, I got your post and clivel's mixed up.  Thus the reference to non-designer apps)

I think I am (slowly) starting to understand how it works.

I've added a call to
Code: [Select]
resize(sizeHint()) which I hadn't done previously.  This seems to handle resizing especially well for the 240x320 display.  I used to do something similar when I coded without Designer.

Is that the best way to handle resizes?  And do you have to do something similar to ensure that the window is completely visible?

A quick sample app is here: all.tgz with the .ui code pasted below.  With the resize this appears to work, but I often get the title of the dialog off the screen.

Code: [Select]

exampleBoxBase

    QDialog
    
        name
        exampleBoxBase
    

    
        geometry
        
            0
            0
            272
            316
        

    

    
        caption
        exampleBox
    

    
        
            margin
            11
        

        
            spacing
            6
        

        
            QGroupBox
            
                name
                GroupBox9
            

            
                title
                test
            

            
                
                    margin
                    11
                

                
                    spacing
                    6
                

                
                    QLabel
                    
                        name
                        TextLabel1
                    

                    
                        text
                        Ad os et bene humo exerci molior et premo. Esse erat iusto vulputate magna molior odio ingenium. Dolore defui, melior fatua feugiat gemino commoveo.
                    

                    
                        alignment
                        WordBreak|AlignVCenter|AlignLeft
                    

                    
                        wordwrap
                    

                

            

        

        
            QGroupBox
            
                name
                GroupBox10
            

            
                title
                sample
            

            
                
                    margin
                    11
                

                
                    spacing
                    6
                

                
                    QMultiLineEdit
                    
                        name
                        MultiLineEdit1
                    

                    
                        wordWrap
                        WidgetWidth
                    

                    
                        text
                        Ut duis vicis ullamcorper et duis duis caecus esse, dolus, venio incassum cui. Praemitto reprobo nullus capio secundum, aliquip exputo adipiscing facilisi pneum, obruo refero, quidem.
                    

                

            

        

        
            QPushButton
            
                name
                Leave
            

            
                text
                Leave
            

        

    



    
        Leave
        clicked()
        exampleBoxBase
        reject()
    


C860 Cacko ROM | 5500 tkcROM
256MB SD | 128MB SD
512MB CF | 256MB CF
D-Link DWL 660 WiFi| Linksys WCF12 WiFi
Socket Bluetooth | Socket Ethernet

ashikase

  • Sr. Member
  • ****
  • Posts: 280
    • View Profile
    • http://
Appropriate resizing of QT dialogs and such
« Reply #6 on: November 12, 2004, 07:51:00 am »
I took a look at your example code, though I'm not quite sure what you want it to do. Is it supposed to create the examplebox as a separate dialog (i.e. not a part of the main dialog that contains the lattice)? If so, and you want the new dialog to fit on the screen, I would suggest calling
Code: [Select]
box->showMaximized()instead of
Code: [Select]
box->show()If you do not want the dialog to fill the whole screen, you will have to resize it manually.

On a side note, in main, you do not need to call mw->show, as showMainWidget() already does that for you.

- ashikase
  anpachi, gifu, japan
SL-C3100 & SL-C760

vanstrien

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • http://www.vanstrien.net
Appropriate resizing of QT dialogs and such
« Reply #7 on: November 12, 2004, 11:22:42 am »
Thanks.  But the problem with this example code is the same problem I've having in all my normal code.  I think that my use of dialog boxes is missing something.  In this example I've been able to get the dialog to resize so that all the text is shown properly by putting a resize(sizeHint()) in the constructor.  Is that what you should normally do?

I'm looking for a way of making my dialog boxes so that they work pretty much the same on a 240x320 screen as they do on the 640x480 screen. (or validation that the resize is the right way)  If I make a dialog larger in Designer, then it may fit on an 860 but is way too big on a 500.  If I shrink the dialog it is the opposite.  By calling resize I now have the problem where half the time the title bar is off screen.  

A better question might be: besides calling show(), is there anything else you should do to make sure that the a dialog box displays as well as possible?   Does it make sense to call a resize() just to ensure that the dialog displays correctly on different screen sizes? (versus setting size policies or something else)
C860 Cacko ROM | 5500 tkcROM
256MB SD | 128MB SD
512MB CF | 256MB CF
D-Link DWL 660 WiFi| Linksys WCF12 WiFi
Socket Bluetooth | Socket Ethernet

ashikase

  • Sr. Member
  • ****
  • Posts: 280
    • View Profile
    • http://
Appropriate resizing of QT dialogs and such
« Reply #8 on: November 12, 2004, 08:20:50 pm »
I'm still not sure that I follow you. You want to make sure that your dialog boxes fit on the screen, but you're saying that you don't want it to be full screen (maximized)? Calling showMaximized() would put the dialog box in maximized mode, so that it would fit perfectly to the screen size.

If you don't want a full-screen dialog, how big do you want your dialog boxes to be? You could always resize the boxes after creation to a percentage of the screen width and height, using the resize function and qApp->desktop() to get the screen size.

You shouldn't have to make a direct call to resize(sizeHint()), as that should be done automatically.

I've found that GUI creation with Qt can be really tricky, and sometimes just downright frustrating. One problem that I've found, at least with Qt 2.x, is that the default sizeHints aren't always appropriate for use on a PDA-size screen. For example, the QMultiLineEdit widget has a default height of 6 lines, unless restricted using a fixed height or setting the maximum number of visible lines. However, if you set a fixed value for the height/number of lines, the app textbox may not grow properly for other resolutions. I ran into this problem in knQuiz, and ended up having to subclass the QMultiLineEdit widget to fix it.

- ashikase
  anpachi, gifu, japan
SL-C3100 & SL-C760

tumnus

  • Hero Member
  • *****
  • Posts: 1176
    • View Profile
    • http://www.cpinkney.org.uk
Appropriate resizing of QT dialogs and such
« Reply #9 on: November 13, 2004, 02:38:20 pm »
Using QT Designer you need to have a look at the Spacer widget and the sizePolicy properties of the other widgets.

With expanding size policies and the Spacers in the appropriate places along with the layout widgets will cause widgets to grow and shrink with the form.

You should never ever use absolute widget and form sizes/positions unless there is a good reason to do so in your application.

If you want I can send you a .ui file I created with QT Designer for an app I started a while ago (and still need to get around to finishing). It resizes without any trouble and does not require any extra code whatsoever so long as it is shown with showMaximized(). As ashikase says, any form will have to be manually scaled if you do not want it to take the full screen but still take about the same percentage of the screen at different resolutions.
# Search the Zaurus Howtos ## Search the Zaurus FAQs ## Find Z software at ELSI #
--------------------
UK SL5500 with Sharp ROM 3.13, SL5600 with Sharp ROM 1.32 - SuSE 9.0 Pro, Windows XP Home
Qualendar for Calendar and Todo
Socket Bluetooth CF Card (Rev F), Kingmax 512MB MMC Card, Palm Tungsten T Stylus,
Pretec CF->Smartmedia Adapter, Semsons Universal Battery Extender

vanstrien

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
    • http://www.vanstrien.net
Appropriate resizing of QT dialogs and such
« Reply #10 on: November 14, 2004, 07:55:06 am »
Tumnus,

Yeah, I would appreciate that.  Would you mind sending it to michael at vanstrien dot net?

I was apprehensive about running dailogs as maximised (if I understand correctly the implications of that) but since it is too much hassle to make non-fullscreen dialogs fit well then I suppose I should just do that.

Thanks for the help.
C860 Cacko ROM | 5500 tkcROM
256MB SD | 128MB SD
512MB CF | 256MB CF
D-Link DWL 660 WiFi| Linksys WCF12 WiFi
Socket Bluetooth | Socket Ethernet