Results 1 to 4 of 4

Thread: QComboBox does not resize with setModel()

  1. #1
    Join Date
    Dec 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QComboBox does not resize with setModel()

    I am using Qt version 4.3.1

    I create a QComboBox with the QComboBox::AdjustToContents property set. The problem is that the size of the combobox is not adjusted when I change the model with setModel() after the combobox is displayed. Calling update() or adjustSize() after setModel() also do not work.

    The only thing that seems to work is to insert and remove a dummy item, but that doesn't look very smart...

    Can anyone tell me if there is a better way to tell QComboBox to adjust its size after a model change?

    Thanks in advance.
    Last edited by Wim; 4th December 2007 at 06:04.

  2. #2
    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: QComboBox does not resize with setModel()

    I agree QComboBox should adjust its size hint when the model is changed. I suggest reporting this to Trolltech via Task Tracker (if not already reported).

    According to QComboBox sources, you could work it around by
    - sending a QEvent::StyleChange, QEvent::FontChange (or QEvent::MacSizeChange)
    - inserting or removing a row to/from the model
    - changing any data of the root model index children
    - changing size adjust policy to something else and then back
    - changing minimum contents length
    - changing icon size
    even though none of them is that smart way. Each of these methods invalidates the current size hint and causes it to be recomputed.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox does not resize with setModel()

    I will submit a bug report to Trolltech. Thanks for your help.

  4. #4
    Join Date
    Dec 2007
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox does not resize with setModel()

    Trolltech has created task ID 190205 to deal with this problem

    They suggest "changing the size adjust policy before setting the new model and then change it back again afterwards, as it seems to be the least "intrusive" workaround".

Similar Threads

  1. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  2. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

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.