Results 1 to 8 of 8

Thread: QDialog and resizing problem...

  1. #1
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QDialog and resizing problem...

    I'm relatively new to this - just been doing Qt4 for a little over a week, so please forgive me if this is something is seemingly obvious to the more skilled. I've really grown to love Qt - it's just so much more logical and well planned than MFC, Win32, or anything else I've worked with.

    FYI - I'm using Qt 4.4.3, Windows Commercial, under VS2008.

    I'm having a trouble with a dialog resizing on me. I'm already using several layout managers - added through QtDesigner - as follows:

    Side Bar:
    +-------------------------+
    | <fix vertical> | <- fixed to keep height from top the same
    | button |
    | <expanding vertical> |
    |<fix horizontal> | <- to line up with the lower bar, fixed to keep width the same
    +-------------------------+


    Lower Bar:
    +----------------------------------------------------------------+
    | <expanding horizontal> button <expanding horizontal> |
    +----------------------------------------------------------------+

    Central Bar:

    +-----------------+
    | QTableWidget |
    +-----------------+
    | Lower Bar |
    +-----------------+

    Main Layout of QDialog:

    +-----------+--------------+
    | Side Bar | Central Bar |
    +-----------+--------------+


    My problem is that the QDialog gets resized whenever I insert a row into the QTableWidget (via QTableWidget::insertRow()).

    Aside from the specifically fixed bars, everything is set to have an QSizePolicy::Expanding size policy, and the size constraints have been set to QLayout::SetNoConstraint.

    The odd behaviour is that the QDialog will shrink below even the size of QTableWidget if I have a minimum size set in the QTableWidget - cutting off the vertical scroll bar.

    It will somewhat abide by a minimum size if I set it - but then the dialog is way too big, and I'd really like to be able to let the user resize the dialog.

    I had had a minimum width set for a while, but the resize issue would still occur as it would resize away any height I had added - meaning I would have to resize only after I had added all the rows I wanted.

    Any tips, help, etc. would be greatly appreciated.

    TIA,

    Ben

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    sounds like the dialog isnt set as the parent of the other widgets..otherwise thats a really odd behaviour..are u sure dialog is the parent of all other widgets and spacers

  3. #3
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    Quote Originally Posted by talk2amulya View Post
    sounds like the dialog isnt set as the parent of the other widgets..otherwise thats a really odd behaviour..are u sure dialog is the parent of all other widgets and spacers
    Pretty sure...

    I've tried adding a new QVBoxLayout that tries to take over the main layout as a child - namely because I also added a menu bar that is not a child of any of the other layouts, and was trying to fit it in as well in trying to resolve this.[1] Any how...in doing so, it complains about already having a parent when I do so. Taking out that code doesn't change the behavior, nor does adding it fix it. (Just changed and checked to verify.)

    I added all the widgets via the Qt Designer, and looking at the UIC generated code (namely the implementation of ui.setup(this)) it seems like things would parent correctly.


    [1] The menu bar was added via the following:
    menuBar = new QMenuBar(this);

    It's only oddity is the bottom of the text sits a little lower than the top of the QTableWidget. I figured this was probably due to its lack of inclusion in the UI's layout, but it doesn't seem to be programmatically solvable by adding another layout.

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    Could u please post the relevant code..its really hard to guess the problem, although i think it will be a really trivial one

  5. #5
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    Quote Originally Posted by talk2amulya View Post
    Could u please post the relevant code..its really hard to guess the problem, although i think it will be a really trivial one
    I'll see what I can do. The program is already complete aside from this issue, and I don't think they'd let me just post it. So I'll see if I can create another one that I can post and exhibits the same issue.

  6. #6
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    Ok...found the issue.

    Essentially, I had setup a call to adjustSize() when inserting a row. The call would then shrink the dialog to its _minimum_ size. However, my expectation was that the layout would inquire of the table its minimum size and the table would consider the contents and make an appropriate adjustment so the dialog would not be extremely out of proportion with its data up to the screen resolution available. However, none of that seems to happen, so it just goes it minimum size.

    Eliminating the adjustSize() call fixes the issue. Is there any way to do what I was expecting it to do?

    Then again, thinking about it now...that's probably something undesirable from the user's pov...one of those things that has a good intention but a bad effect...

    TIA,

    Ben

  7. #7
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    I figured out how to reproduce it now. Below is a link to some sample code. Note the code around 'table->insert(...)'. The 'adjustSize()' doesn't seem to bother it, but the calls to adjusting the table size information do. I tested this project on Windows using Qt 4.4.3, but I'm sure it would work the same under Linux too.

    http://tinyurl.com/cfa5w4

    Essentially, what I wanted was to be able to adjust the table cells to the contents, and let the user decide about the size of the dialog. However, doing so seems to adversely affect the size of the dialog itself.

  8. #8
    Join Date
    Feb 2009
    Posts
    29
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDialog and resizing problem...

    Sorry, should have done this as part of the last post...occurred to me just as I hit the 'quick reply' button...

    For completeness - as I'm not going to keep that tarball online forever - here's the specific code that I added to cause the problem again:

    Qt Code:
    1. void testTable::doInsertRow()
    2. {
    3. if (table != NULL)
    4. {
    5. table->insertRow(table->rowCount());
    6. table->resizeColumnsToContents();
    7. table->resizeRowsToContents();
    8. table->adjustSize();
    9. }
    10. adjustSize();
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Resizing a QDialog to the content size
    By Nyphel in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2007, 08:16

Tags for this Thread

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.