Results 1 to 9 of 9

Thread: QListWidget size

  1. #1
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default QListWidget size

    I have tried finding the answer to this and as a last resort i am posting here to see if any one can help.

    I have a QLlstWidget to which I add 4 QListWidgetItems

    I want to set these QListWidgetItems to fill the space available in the list

    I am trying to do the following:

    QListWidgetItem->setSizeHint(QSize((listWidget->width()),(listWidget->height()/4)));

    however, listWidget->height() returns a size much bigger than the QListWidget.

    Is this a bug or am i implementing this wrong?
    Last edited by dubstar_04; 6th March 2010 at 16:57.

  2. #2
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QListWidget size

    does anyone have any advice to solve my problem?

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget size

    Try to check the area of the viewport QAbstractScrollArea::viewportIt might be that the QListWidget has more area and scrollbars will be used to navigate it. So check what you get with the viewport

  4. #4
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QListWidget size

    Thanks for the reply, however that still hasnt solved my problem.

    it might make it easier for you to advice if you can see some code;

    This is the code from the function that sets up the ui and its elements;

    Qt Code:
    1. // Setup Pages
    2. mainMenuWidget = new QWidget(this);
    3. timelineWidget = new QWidget(this);
    4. directMessagesWidget = new QWidget(this);
    5. searchWidget = new QWidget(this);
    6. settingsWidget = new QWidget(this);
    7.  
    8. // Setup Layouts
    9. mainLayout = new QVBoxLayout;
    10. mainMenuLayout = new QVBoxLayout(this);
    11. timelineLayout = new QVBoxLayout(this);
    12. directMessagesLayout = new QVBoxLayout(this);
    13. searchLayout = new QVBoxLayout(this);
    14. settingsLayout = new QVBoxLayout(this);
    15.  
    16. // Setup visual widgets
    17. timelineLabel = new QLabel("Timeline",this);
    18. directMessagesLabel = new QLabel("Direct Messages",this);
    19. searchLabel = new QLabel("Search", this);
    20. settingsLabel = new QLabel("Settings", this);
    21. backButton = new QPushButton("Back");
    22.  
    23. // Setup the Mainmenu
    24. QListWidget *listWidget = new QListWidget(this);
    25. //listWidget->setMinimumSize(this->width(), this->height());
    26. std::cout << listWidget->width() << " " << listWidget->height() << std::endl;
    27. std::cout << this->width() << " " << this->height() << std::endl;
    28. listWidget->setAlternatingRowColors(true);
    To copy to clipboard, switch view to plain text mode 

    I then add the listwidgetitems to the list.

    The widget is set to showMaximized(); and i want to make the listwidgetitems fit nicely regardsless of the screensize that the app is running on.

    Qt Code:
    1. QListWidgetItem *timelineButton = new QListWidgetItem(listWidget, 1000);
    2. timelineButton->setIcon(QIcon(":/images/menu/timeline.png"));
    3. timelineButton->setText("Timeline");
    4. //timelineButton->setFont(QFont("Lucida Grande", (listWidget->height()/10), QFont::Bold));
    5. timelineButton->setTextAlignment(Qt::AlignCenter);
    6. //timelineButton->setSizeHint(QSize(0,((listWidget->height())/4)));
    7. listWidget->addItem(timelineButton);
    To copy to clipboard, switch view to plain text mode 

    the calls to listWidget->height(); and listWidget->viewport->height(); always return the same value regards of what size the widget is set to start at.

    for example if i w.resize(400,500); before calling w.show() the size return is the same as when the window is started with w.showMaximized();


    Does this shed anymore light on the problem?

    Thanks,

    Dubstar_04

  5. #5
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QListWidget size

    This is what i am aiming to achive. A filled QListWidget with no scroll bars and the QListWidgetItems filling the QListWidget neatly and properly.



    Is there a better way to get a nice finger friendly menu?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget size

    For listwidget with no scroll bar, check out for flick charm demo in Qt Labs. Or you may be able to find you might find flickable example in Qt demos from 4.6.2.
    For finger friendly you need to have bigger height of items. Arent you getting the same with setSizeHint ?

  7. #7
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QListWidget size

    Thanks for the flick charm example it looks great, however, it still doesnt answer my initial question of how to size a predefined number of QListWidgetItems to fill a static list.

    if you could help me solve this i would be very grateful.

    Thanks,

    Dubstar_04

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget size

    I will try an example if I get time.. meanwhile can you tell how would you want to fill listwidget with height say 600 and having 10 items with height say 60. But if listwidget size get reduced to 200, would you want item height to be 20 ?

    Meanwhile I had few questions...
    why did you have - //timelineButton->setSizeHint(QSize(0,((listWidget->height())/4))); ?
    instead of zero, it should have been timelineButton->->sizeHint().width() I guess... try that and see if it works..

  9. #9
    Join Date
    Feb 2010
    Posts
    27
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QListWidget size

    I will try an example if I get time.. meanwhile can you tell how would you want to fill listwidget with height say 600 and having 10 items with height say 60. But if listwidget size get reduced to 200, would you want item height to be 20 ?

    Yes that is exactly what i am trying to do. Size the list items according to the listwidget size.

    Meanwhile I had few questions...
    why did you have - //timelineButton->setSizeHint(QSize(0,((listWidget->height())/4))); ?
    instead of zero, it should have been timelineButton->->sizeHint().width() I guess... try that and see if it works..


    I actuall had it as:

    Qt Code:
    1. timelineButton->setSizeHint(QSize((listWidget->width()),((listWidget->height())/4)));
    To copy to clipboard, switch view to plain text mode 

    I would really appreciate it if you could asist me in finding a solution as i seem to have hit a wall with this yet i am sure the solution will be simple.

    Thanks,

    Dubstar_04

Similar Threads

  1. set QListWidget/QTreeWidget icon size
    By rbp in forum Qt Programming
    Replies: 4
    Last Post: 14th October 2009, 02:05
  2. Replies: 2
    Last Post: 11th September 2007, 08:57
  3. Default size of a QListWidget inside a QDockWidget
    By rakuco in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 08:01
  4. How to set QListWidget size MAX = QMainWindow ?
    By Kenneth in forum Qt Programming
    Replies: 3
    Last Post: 16th March 2007, 10:11
  5. Qt 4.2: QListWidget changes size of its items
    By KingFish in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 11:06

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.