Results 1 to 4 of 4

Thread: QDockWidget - dynamic size

  1. #1
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QDockWidget - dynamic size

    Hi all,

    I have a QDockWidget (within a QMainWindow) that contains a custom outterWidget QWidget. The outterWidget has
    1) an innerWidget QWidget which contains x number of widgets (QLineEdit and QLabel widgets) depending on the program condition
    2) a horizontal line
    3) a push button

    for layouts, outterWidget is set to QGridLayout
    Qt Code:
    1. QGridLayout *gridLayout = new QGridLayout(this);
    2. gridLayout->setSpacing(5);
    3. gridLayout->setMargin(2);
    4. gridLayout->addWidget(innerWidget, 0, 0, 1, 3);
    5. gridLayout->addWidget(ui.line, 1, 0, 1, 3);
    6. gridLayout->addWidget(ui.runBtn, 2, 1, 1, 1);
    To copy to clipboard, switch view to plain text mode 
    innerWidget QWidget also has a QGridLayout that takes in an integer of how many row QLineEdit and QLabel to create
    Qt Code:
    1. QGridLayout *mainLayout = new QGridLayout(this);
    2. mainLayout->setSpacing(5);
    3. mainLayout->setMargin(2);
    4. for (int i=0; i<nParams; ++i)
    5. {
    6. int col = 0;
    7. QLabel* label = new QLabel("test");
    8. QLineEdit* lineEdit = new QLineEdit();
    9. mainLayout->addWidget(label, i, col++);
    10. mainLayout->addWidget(lineEdit, i, col++);
    11. }
    To copy to clipboard, switch view to plain text mode 

    In my program, when the # of widgets within the innerWidget increases, the QDockWidget resizes probably, BUT when the # of widgets within the innerWidget decreases, the QDockWidget doesn't reduce its size probably so there are blanks on the . I have tried to called updateGeometry, update, resize etc ... but nothing helps.

  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: QDockWidget - dynamic size

    Probably adjustSize() is working, not sure? And have you seen QFormLayout for your inner layout?

  3. #3
    Join Date
    Jan 2009
    Posts
    47
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDockWidget - dynamic size

    adding "adjustSize()" on the QMainWindow seems to work. However, it introduces the unpleasant effect of the QMainWindow resizes.

    The attached code has a QMainWindow that contains:
    1) a label
    2) a text box
    3) 2 dock widgets
    3a) one of them is empty, a place holder for some other stuff
    3b) a dock widget with a scrollarea that contains an outter widget with:
    3b1) a label & combo box
    3b2) a dynamic inner widget
    3b3) a label & combo box
    I set the minimum size of this dockWidget to 180, 125 which should have enough room for the smallest size of the inner widget, ~80% cases. It seems to work fine EXCEPT for

    Issue # 1) let say I run it with 1 widget to create dynamically in the inner widget, un-dock it, and re-dock it causes a change in the size of the scrollarea

    Issue # 2) when un-dock, I'd like it to resize the dock widget so that no scrollbar is needed. Then when re-dock, I want it to go back to its original size

    Thoughts? Thanks in advance.
    Attached Files Attached Files

  4. #4
    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: QDockWidget - dynamic size

    A quick note: use the QDockWidget::dockLocationChanged() signal and save the geometry when the docking area is changed, so you can restore it afterwards, or adjust the size if the dock widget is floating.

Similar Threads

  1. QDockWidget size
    By user in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2009, 20:35
  2. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  3. Default size of a QListWidget inside a QDockWidget
    By rakuco in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 08:01
  4. QDockWidget Size
    By kiker99 in forum Qt Programming
    Replies: 9
    Last Post: 31st March 2007, 16:15
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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
  •  
Qt is a trademark of The Qt Company.