Results 1 to 4 of 4

Thread: Updating layout after adding context to a QComboBox

  1. #1
    Join Date
    Feb 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Updating layout after adding context to a QComboBox

    Hello,

    I have a QComboBox where the size adjust policy is set to 'AdjustToContent'. During execution of my program I add content to this widget. It resizes to fit the content even though there is insufficient space for it to do so. That is, it overlaps with the widget next to it. Resizing the screen causes the QComboBox to shrink. It is now as large as possible without overlapping the next widget. This is the behaviour I would expect.

    My question is how to I get it to be 'as large as possible' immediately after adding new content. I've tried calling updateGeometry(), update(), layout()->update(), etc... without any effect. It seems like I need to have the layout recalculate the best size for all widgets, but am unsure of how to do this (I though that was the point of layout()->update()).

    Thanks for any and all help.

    Cheers,
    Donovan

  2. #2

    Default Re: Updating layout after adding context to a QComboBox

    Hi,
    Just curious if you were able to figure out the solution for this problem?? I am having the same problem

    Best,
    CV

  3. #3
    Join Date
    Nov 2006
    Location
    indonesia
    Posts
    55
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating layout after adding context to a QComboBox

    Hi,
    This is simple. You must set QComboBox SizeAdjustPolicy. This is a sample code :
    Qt Code:
    1. ui->comboBox->addItem(str);
    2. ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    To copy to clipboard, switch view to plain text mode 

    With this code, your layout display will update after adding new item.
    Thank you.

    Best regards,

    Toto

  4. #4

    Default Re: Updating layout after adding context to a QComboBox

    Quote Originally Posted by myta212 View Post
    Hi,
    This is simple. You must set QComboBox SizeAdjustPolicy. This is a sample code :
    Qt Code:
    1. ui->comboBox->addItem(str);
    2. ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    To copy to clipboard, switch view to plain text mode 

    With this code, your layout display will update after adding new item.
    Thank you.

    Best regards,

    Toto
    Well I already have SizeAdjustPolicy set to 'AdjustToContents' for my combobox. So when the item text changes it resizes and overlaps with another item in the widget. Once I resize the whole window manually thats when the combobox updates and resizes so that it doesn't overlap. I tried update(), repaint() for the widget and the combobox after the item is added but doesn't help. I have to manually resize for it to readjust with the layout

    CV

Similar Threads

  1. Adding actions to a context menu
    By aarelovich in forum Qt Programming
    Replies: 4
    Last Post: 7th December 2011, 12:47
  2. Replies: 3
    Last Post: 28th December 2010, 11:55
  3. Replies: 0
    Last Post: 12th December 2010, 05:09
  4. Problem updating a layout
    By Wach in forum Qt Programming
    Replies: 7
    Last Post: 17th August 2010, 00:38
  5. Replies: 0
    Last Post: 7th April 2008, 14:27

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.