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: Styling contents
QtWS25 Last Chance

QTreeView: Styling contents

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 8.9k 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.
  • N Offline
    N Offline
    nonot1
    wrote on last edited by
    #1

    Hello,

    Is it possible to style the contents of a QtreeView using style sheets?

    The docs show examples of styling the tree widget, but necessarily the items.
    http://doc.qt.nokia.com/4.7/stylesheet-examples.html#customizing-qtreeview

    For instance, certain columns should have bold text or custom checkbox images.

    Failing that, can I supply a widget instance such as a QLabel, or even QPushButton, for particular data items? (Overriding the paint() method using delegates seems a bit heavy handed.)

    Thank you

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yshurik
      wrote on last edited by
      #2

      If you have some different groups of items with different properties then you need to use delegate or at least overwrite some roles in model (like Qt::FontRole to make bold for some items). Style sheets are more generic and not connected to logic "which items should get properties"

      Regarding item delegates - No need to overwrite paint() if you would like to insert just QPushButton - just create in desired widget in createEditor() - you can insert even while complicated panel with widgets etc.

      If you need custom checkbox images - you may create QCheckBoxes in delegate and apply stylesheets to them in that place

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

        [quote author="yshurik" date="1304978093"]
        Regarding item delegates - No need to overwrite paint() if you would like to insert just QPushButton - just create in desired widget in createEditor() - you can insert even while complicated panel with widgets etc.

        If you need custom checkbox images - you may create QCheckBoxes in delegate and apply stylesheets to them in that place[/quote]

        This all only works if in edit mode. all other cells will be drawn by default.
        There is the possibility of setting widgets to cells by "setIndexWidget":http://doc.qt.nokia.com/4.7/qabstractitemview.html#setIndexWidget . These widgets should be displayed the whole time.

        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
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          If you are able to manipulate the style enough by using the styling roles, then I would go that route. It is the easiest to accomplish. You could make a QSortFilterProxyModel subclass that simply sets the required data roles for the columns you need it for (such as a bold font in a certain column). Depending on the number of items in your view, using widgets can get too expensive.

          See "this topic":http://developer.qt.nokia.com/forums/viewthread/4788/ for an example on how to use a QSFPM to assign colors to cells.

          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