Results 1 to 9 of 9

Thread: Resizing a QDialog to the content size

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Resizing a QDialog to the content size

    Hello,

    I have a QDialog based ui.
    The QDialog only contains a QTableWidget within a QVBoxLayout.

    My table is compouned of an unknown number of rows, and I resize them with "resizeRowsToContents()" every time the content of the table has changed.
    That's ok.

    The problem is to resize the height of the QDialog to match the new size of the table.
    In order to do that, I sum the height of the rows and I get the size really used by the table.

    So, I just need to resize my QDialog...
    It's new height will be equals to the table's necessary height more any pixels for the QDialog's style (that adds border on the top and the bottom of the content, for title, menus, etc...).

    I can't find any function that would give me the avaible geometry of the QDialog, in order to compute :
    Added height = QDialog's height - avaible geometry.height
    So I compute something like :
    Added height = QDialog's height - QTable's height

    The matter is that the QTable->height doensn't give me the height of the Widget.
    It returns me 30.
    The sum of the rows is about 66.
    The QTable size is about 180. (I know that with the QDesigner)
    The QDialog size is about 200. (I know that with the QDesigner)

    I used the size() and geometry() functions in order to get the QTable's height.
    Every time I try to know the height value, I get 30

    May you help me please ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Resizing a QDialog to the content size

    Hi,

    maybe adjustSize() works for you.

    Lykurg

  3. The following user says thank you to Lykurg for this useful post:

    rawfool (7th January 2015)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a QDialog to the content size

    You can't retrieve the size of a widget before it is shown for the first time.

  5. #4
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizing a QDialog to the content size

    If I show it one, two... three times before getting the size, i've got the same result .
    I'll try "adjustSize()"

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Resizing a QDialog to the content size

    Quote Originally Posted by Nyphel View Post
    If I show it one, two... three times before getting the size, i've got the same result .
    A widget is not shown immediately after calling show(). A show event is scheduled and the widget comes visible later when the control returns to the event loop.
    J-P Nurmi

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a QDialog to the content size

    You can override showEvent() and set the size there if you want.

  8. #7
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizing a QDialog to the content size

    Oki, thanks.

    I override the showEvent and now it works fine.
    I set fit the columns/rows size to the content, and then I fit the QDialog to the QTable content size.

    I don't understand why that didn't work before.
    I'm sure that the QDialog was shown before trying to resize it .

    Thanks everybody

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a QDialog to the content size

    How did you make sure it was shown before resizing it?

  10. #9
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Resizing a QDialog to the content size

    Because I show it with a button,
    and then I push another button to resize it ^_^

Similar Threads

  1. Replies: 1
    Last Post: 24th October 2006, 17:40
  2. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14
  3. Dynamically resizing in QT 3
    By kroenecker in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 19:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.