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. QTreeView delegate with background covering only text - howto

QTreeView delegate with background covering only text - howto

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 648 Views 3 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.
  • gbettegaG Offline
    gbettegaG Offline
    gbettega
    wrote on last edited by aha_1980
    #1

    Hello forum,
    I've the classic QTreeView, QStandardItemModel pair. QTreeView has one column.
    I'd like that when the user selects an item the background covers only the text, not the entire row,. The result I would like to obtain is shown in the figure. Any kind of suggestion is strongly appreciated, starting from a straightforward one (a qss for example) to a detail within the implementation of a custom delegate. For the moment I've not been able to obtain any result.
    Thanks in advance
    Giovanni
    0_1555065059530_highlight only text.PNG

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Can you show what you are actually getting ?

      Unless you changed the selection mode, it should only select a cell.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      gbettegaG 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Can you show what you are actually getting ?

        Unless you changed the selection mode, it should only select a cell.

        gbettegaG Offline
        gbettegaG Offline
        gbettega
        wrote on last edited by gbettega
        #3

        SGaist thank you
        see attachment
        Giovanni0_1555152188984_Cattura.PNG
        As you can see the blue selection box extends up to the end of the column, also with a surrounding box. I would like a shorter selection box (with or without surrounding rectangle) starting from the beginning of the text, and ending at the end of the text.
        Regards
        Giovanni

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then a custom QStyleItemDelegate is what you want. Re-implement the paint method to draw the selection the way you want it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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