Results 1 to 7 of 7

Thread: Rendering items on QListView

  1. #1
    Join Date
    Apr 2007
    Location
    Brazil
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Rendering items on QListView

    Hi,

    I am starting to develop with Qt so I am sorry if my doubt is too obvious.

    I am developing an UI on which there is a list that display "complex" items. I said "complex" because each item has an uncommon design and a lot of information and pictures. I have read about QListView and found I can only easily use Strings item on it. After research a little more I found out that using a QItemDelegate I would have more control on what I will render for each item using paint method.

    However I would like to create a composite Widget (with layout, picture and labels) and render it as an item using ItemDelegate::paint (or another method you suggest me).

    Any help is appreciated!

    Thanks in advance.

    Rafael

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rendering items on QListView

    You cannot paint a widget in QAbstractItemDelegate: paint().
    As far as I can see, you have two solutions:

    1. Do all the painting in QAbstractItemDelegate: paint().

    2. Create your widget, with everything you want in it, and then don't actually use this widget but use QPixmap::grabWidget to get a pixmap of this widget and draw this pixmap in QAbstractItemDelegate: paint(). This way would be simplwer to handle the look of the item ( you said you wanted layouts, labesl, etc )

    Regards

  3. The following user says thank you to marcel for this useful post:

    rcintra (10th May 2007)

  4. #3
    Join Date
    Apr 2007
    Location
    Brazil
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Rendering items on QListView

    I was actually expecting some solution a little more elegant !

    I will first try solution #1 since it seems to be faster. If it turns out to be too complex I will go with #2.

    Thanks a lot, Marcel.

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rendering items on QListView

    I was actually expecting some solution a little more elegant !
    It can't get more elegant than this, trust me!
    If you read the docs well before you start you will end-up with a pretty elegant piece of code... Because painting with QPainter is something easy and extremely used in Qt.

    Regards

  6. The following user says thank you to marcel for this useful post:

    rcintra (10th May 2007)

  7. #5
    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: Rendering items on QListView

    If an item has lots of information, maybe it's better to do it without the model-view architecture? How about using a scrollarea and a layout? The model approach is basicaly intended (but not limited to) simple (mostly non-widget) items.

  8. #6
    Join Date
    Apr 2007
    Location
    Brazil
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Rendering items on QListView

    I am implementing a bank account list that each item displays the bank logo and some information about the account (number, balance, etc). I need to strictly follow a UI specification made by the project designer. I decided to use QListView because I need to be able to select an item on the list. Do you guys think that I could use a scrollarea and put the items on it as widgets dynamically? (this way I think I would have to handle the select feature by myself)

    Thanks for the help again!

  9. #7
    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: Rendering items on QListView

    Quote Originally Posted by rcintra View Post
    Do you guys think that I could use a scrollarea and put the items on it as widgets dynamically?
    I do. At least I'd do it this way if I had a complex widget.

    (this way I think I would have to handle the select feature by myself)
    I don't think adding a checkbox into the layout is that much of a problem

  10. The following user says thank you to wysota for this useful post:

    rcintra (10th May 2007)

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 14:46
  2. Items in QListView should sort on Header Click
    By vinnu in forum Qt Programming
    Replies: 14
    Last Post: 10th November 2006, 13:49
  3. Selective highlighting of Items
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2006, 13:20
  4. moving Qlistview items
    By :db:sStrong in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2006, 13:25
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 15:45

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.