Results 1 to 8 of 8

Thread: How to Modify QListView item height?

  1. #1

    Red face How to Modify QListView item height?

    hello, all,
    I want to modify QListView item height or spacing between items. How to modify it?
    qstyle? I don't find the property...

  2. #2
    Join Date
    May 2008
    Posts
    42
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4

    Default Re: How to Modify QListView item height?

    Hi,

    QListView is derived class of QWidget.
    So you can use setFixedHeight ( int h ) i think..

    Thanks,
    Santhosh

  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: How to Modify QListView item height?

    How are you using QLIstView ?
    If you are using model, you need to return size hint from the data() function of the model.

    something like
    if(role == Qt::sizeHintRole)
    return QSize(width,height);

  4. #4

    Default Re: How to Modify QListView item height?

    I think this could only affects the total height of widget, not item height...

    Quote Originally Posted by santhoshv84 View Post
    Hi,

    QListView is derived class of QWidget.
    So you can use setFixedHeight ( int h ) i think..

    Thanks,
    Santhosh

  5. #5

    Default Re: How to Modify QListView item height?

    Just new a QListView in an Object. I wonder why setSpacing(...) function doesn't work..

    Quote Originally Posted by aamer4yu View Post
    How are you using QLIstView ?
    If you are using model, you need to return size hint from the data() function of the model.

    something like
    if(role == Qt::sizeHintRole)
    return QSize(width,height);

  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: How to Modify QListView item height?

    Can you show us some code of what u are doing ?
    hard to say whats wrong without seeing more

  7. #7
    Join Date
    Jan 2012
    Location
    St. Petersburg, Russia
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: How to Modify QListView item height?

    Try this in the last resort:

    Qt Code:
    1. QListView listView;
    2. listView->setStyleSheet("QListView::item { height: 100px; }");
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to Modify QListView item height?

    If you're using a delegate, try to override the sizeHint method.

    Header:
    Qt Code:
    1. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
    To copy to clipboard, switch view to plain text mode 

    Source:
    Qt Code:
    1. QSize MyDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
    2. {
    3. return(QSize(100, 50));
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. how to modify menu item height
    By blackfox in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2008, 10:02
  2. how to move item up and down in QListView
    By zhanglr in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2008, 14:39
  3. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  4. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 03:13

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.