Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "complete control" owner drawing of QListWidget rows

"complete control" owner drawing of QListWidget rows

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    I need a view that's something like Skype's contact view. List of names, with an image at their side, and some buttons that become visible as you select a row. Using QListWidgetItem does answer some of these requirements but is severely limited, by icon width and others.

    One other thing that's less of a priority -- QListWidget scrolls in rigid steps. The scroll is not smooth and you can never see "half a row" like you can in Skype. It's like QListWidget scrolls up and down in row-height steps, while Skype scrolls in single pixels. Much smoother and pleasing from a UX standpoint. I know Skype is QT. Are they using a different control for this?

    How do I achieve complete control over the drawing of a row in QListWidget?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      ronM71
      wrote on last edited by
      #2

      @setVerticalScrollMode(QAbstractItemView::ScrollPerPixel)@ took care of the smooth scrolling problem. now the owner draw issues remain.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Concerning the scrolling, check out QAbstractItemView::setVerticalScrollMode ( ScrollMode mode )

        If you need complete control, you need to use QItemDelegate.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ronM71
          wrote on last edited by
          #4

          Thanks. Will give those a try. Any idea how how implement custom sorting on such a list?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            It depends a bit on what you want to do. If you can get away with it, the easiest way is to set something you can sort on as a custom role and use that role to sort on. If not, you will need to reimplement sort() on your data model.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              ronM71
              wrote on last edited by
              #6

              Not so sure about a model. I have a QListWidget to which i "add" instances of QListWidgetItem. Are you saying I can instantiate an external "Data model", populate it with my data, and then have the QListWidget use that as the source to populate rows instead of me "adding" it manually there?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Errr... Sorry, no. I never use Q*Widget myself, so I am not so used to the limitations of these classes. I was thinking about the View versions where you can set your own model.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ronM71
                  wrote on last edited by
                  #8

                  I can do that, so should I replace my QListWidget with the QListView?

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    That makes life sometimes a bit easier, especially when you do more complex things.

                    You use a QListView as widget and create a custom model derived from QAbstractListModel, that's not too hard, especially if it's read only.

                    Then you can use a QSFPM (QSortFilterProxyModel) which you use in the view to do sorting. If you use QSFPM you have full access to the sorting criteria.

                    Via a custom delegate (derived from QStyledItemDelegate) you can do custom drawing, change the size hint for rows etc.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved