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. QListWideget and QListWidgetItem
Forum Updated to NodeBB v4.3 + New Features

QListWideget and QListWidgetItem

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.7k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

    I need to customize the way the QListWidgetItem is painted. I found QStyledItemDelegate and I was wandering if QStyledItemDelegate is the way to go or I can customize the item trough an xml layout like in android. Thanks in advance.

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

      The answer depends on what you like to change. If you want to change only colors (like background, text color) it can be done via properties of the items. If you want a complete custom drawing (like gradients, or whatever), you must use a delegate.

      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
      • M Offline
        M Offline
        Mario84
        wrote on last edited by
        #3

        AFAIK there is no way to use delegates with QListWidget (or QTableWidget / QTreeWidget).
        You can only customize your items with the properties QListWidgetItem has.
        If you want to do more, you'll have to use QListView with either QStandardItemModel or your own implementation of QAbstractItemModel. Then you can use QAbstractItemView::setItemDelegate()

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blackbelt
          wrote on last edited by
          #4

          [quote author="Gerolf" date="1351064579"]The answer depends on what you like to change. If you want to change only colors (like background, text color) it can be done via properties of the items. If you want a complete custom drawing (like gradients, or whatever), you must use a delegate.[/quote]

          thanks. I have to draw an icon and a text. Text should be vertical aligned with the icon. Any idea? I have alerady a QStyledItemDelegate, I was just wandering what is better

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

            Icons can be added as decoration role, the you have icon and text side by side (typically icon on the left).
            Otherwise the delegate has a paint method. Overwrite it and do, what is needed there.

            @Mr.Universe: QListWidget is a QListView and you can use delegates for them, just not own models.

            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
            • M Offline
              M Offline
              Mario84
              wrote on last edited by
              #6

              [quote author="Gerolf" date="1351065505"]

              @Mr.Universe: QListWidget is a QListView and you can use delegates for them, just not own models.[/quote]

              oops, you're right. Never tried that before...

              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