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. QListView with custom item delegate

QListView with custom item delegate

Scheduled Pinned Locked Moved Solved General and Desktop
qlistviewitem delegate
4 Posts 2 Posters 7.0k 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by
    #1

    I am using a QListView with a custom QAbstractItemModel to display messages I parsed from a compiler output. Looks like this:

    However, I'd like to have a bit more control over the text styles. For example, I'd like to use two different fonts within the same item and also different font colors. The QAbstractItemModel itself is not capable of handling this. From previous experiences with QTreeView and QTableView I would have thought that I simply write my own custom QStyledItemDelegate that takes care of the painting of the widget. However, it seems that QListView doesn't allow setting custom item delegate. Is that correct? If so, why? And how can I still archive what I want?

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    kshegunovK 1 Reply Last reply
    0
    • Joel BodenmannJ Joel Bodenmann

      I am using a QListView with a custom QAbstractItemModel to display messages I parsed from a compiler output. Looks like this:

      However, I'd like to have a bit more control over the text styles. For example, I'd like to use two different fonts within the same item and also different font colors. The QAbstractItemModel itself is not capable of handling this. From previous experiences with QTreeView and QTableView I would have thought that I simply write my own custom QStyledItemDelegate that takes care of the painting of the widget. However, it seems that QListView doesn't allow setting custom item delegate. Is that correct? If so, why? And how can I still archive what I want?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Joel-Bodenmann said:

      I would have thought that I simply write my own custom QStyledItemDelegate that takes care of the painting of the widget.

      I would've thought so too.

      However, it seems that QListView doesn't allow setting custom item delegate. Is that correct? If so, why?

      Hm, is QAbstractItemView::setItemDelegate not working?

      Read and abide by the Qt Code of Conduct

      Joel BodenmannJ 1 Reply Last reply
      1
      • kshegunovK kshegunov

        @Joel-Bodenmann said:

        I would have thought that I simply write my own custom QStyledItemDelegate that takes care of the painting of the widget.

        I would've thought so too.

        However, it seems that QListView doesn't allow setting custom item delegate. Is that correct? If so, why?

        Hm, is QAbstractItemView::setItemDelegate not working?

        Joel BodenmannJ Offline
        Joel BodenmannJ Offline
        Joel Bodenmann
        wrote on last edited by
        #3

        @kshegunov said:

        Hm, is QAbstractItemView::setItemDelegate not working?

        Oh god... I'm a completely retarded idiot. I was going through the API of the QListView and in the complete brain-dead mode I must have been I forgot to check the base classes...

        I'm sorry for the trouble!

        Industrial process automation software: https://simulton.com
        Embedded Graphics & GUI library: https://ugfx.io

        kshegunovK 1 Reply Last reply
        0
        • Joel BodenmannJ Joel Bodenmann

          @kshegunov said:

          Hm, is QAbstractItemView::setItemDelegate not working?

          Oh god... I'm a completely retarded idiot. I was going through the API of the QListView and in the complete brain-dead mode I must have been I forgot to check the base classes...

          I'm sorry for the trouble!

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Joel-Bodenmann

          Sometimes it's hard to track down inherited members from the base page of the class. When you're in doubt you can go to the "List of all members, including inherited members" page. ;)

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2

          • Login

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