Results 1 to 5 of 5

Thread: QCombobox contents not adjusting itself properly

  1. #1
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QCombobox contents not adjusting itself properly

    I am creating a combo box with the default properties. The problem comes when the options in the combo box has more width then the combobox width. I do not want the combobox to resize as it has fixed width. I can see that for all the options the Combobox itself add abbreviated text, but for the selected text it gives a truncated effect, I want a consistent behaviour i.e the abbreviated text even on the selected option.
    Does anybody has an idea about this?
    Please see the attached screenshot .
    Attached Images Attached Images

  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 contents not adjusting itself properly

    Take a look at QComboBox::sizeAdjustPolicy.
    J-P Nurmi

  3. #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: QCombobox contents not adjusting itself properly

    I'm afraid it might be hard to achieve. The "selected" text is handled by a line edit that should truncate the text that doesn't fit instead of eliding it like the popup does through the delegate. You can probably subclass QComboBox and try to reimplement the paint event, but success is not guaranteed. It might be a good idea to suggest a needed change to Trolltech to allow eliding text in the combobox though. If GUI design rules allow it, there is no reason not to implement it.

  4. #4
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QCombobox contents not adjusting itself properly

    I have used following logic to address this problem, it worked for me,

    QComboBox cb;
    cb.setMinimumContentsLength(20); // set anything > 0
    cb.setSizeAdjustPolicy(QComboBox::AdjustToMinimumC ontentsLength);

  5. #5
    Join Date
    Apr 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QCombobox contents not adjusting itself properly

    comboBox->view()->setTextElideMode(Qt::ElideNone);

Similar Threads

  1. Contents not Properly Visible in QComboBox
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 25th September 2007, 13:32
  2. Adjusting window to QGraphicsView contents
    By IrYoKu in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2007, 13:10

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.