Results 1 to 6 of 6

Thread: QListWidget width

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QListWidget width

    Hi

    What, precisely, controls the default width of a QListWidget. I want a list widget that makes itself exactly wide enough to display the width of its widest item but no more.

    E.g. I would have expected the following simple code to produce a dialog with a list box exactly wide enough to hold the items "fred" and "bloggs" but no more. Yet the dialog that gets shown has a list widget some 5 times wider than necessary. Why?

    Qt Code:
    1. QDialog dlg(this);
    2. QListWidget* pListWidget = new QListWidget();
    3. new QListWidgetItem("Fred", pListWidget);
    4. new QListWidgetItem("Bloggs", pListWidget);
    5. QVBoxLayout* pLayout = new QVBoxLayout();
    6. pLayout->addWidget(pListWidget);
    7. dlg.setLayout(pLayout);
    8. dlg.exec();
    To copy to clipboard, switch view to plain text mode 

    What is the simplest, clean and reliable way to control the list width width without relying on pixel width constants. Code needs to be properly portable. Thanks
    Attached Images Attached Images

Similar Threads

  1. QToolBox width fixed to maximum content width
    By ghorwin in forum Qt Programming
    Replies: 0
    Last Post: 10th July 2009, 09:58
  2. How to set QTableView width to width of horizontal header?
    By martinb0820 in forum Qt Programming
    Replies: 0
    Last Post: 2nd December 2008, 20:51
  3. Replies: 11
    Last Post: 21st February 2007, 11:26
  4. width()
    By mickey in forum Newbie
    Replies: 7
    Last Post: 27th July 2006, 15:18
  5. width()
    By mickey in forum Newbie
    Replies: 1
    Last Post: 1st April 2006, 00:34

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.