Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QTreeView: Styling contents

    General and Desktop
    4
    4
    8732
    Loading More Posts
    • 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
      nonot1 last edited by

      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 Reply Quote 0
      • Y
        yshurik last edited by

        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 Reply Quote 0
        • G
          giesbert last edited by

          [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 Reply Quote 0
          • A
            andre last edited by

            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 Reply Quote 0
            • First post
              Last post