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. [Solved] QTreeWidget add separator between items
Forum Updated to NodeBB v4.3 + New Features

[Solved] QTreeWidget add separator between items

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 14.4k 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.
  • C Offline
    C Offline
    Code_ReaQtor
    wrote on last edited by
    #2

    bq. i need to add separator between items

    The image looks like a QToolBox with QListWidgets/QListView, I think. But also looks like QTreeWidget/QTreeView.

    Sorry but I am not a user of uTorrent so it was based on what I see.

    Please visit my open-source projects at https://github.com/Code-ReaQtor.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adrien Leravat
      wrote on last edited by
      #3

      I would say that's more like multiple QTreeWidget in a QVBoxLayout (at least easier to do)

      @Code_ReaQtor: Also true, but without visible sections.

      Adeneo Embedded - www.adeneo-embedded.com

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #4

        To me, it seems you can easily create this by implementing your own delegate to style your top-level items in your tree.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bepehr
          wrote on last edited by
          #5

          [quote author="Andre" date="1359032142"]To me, it seems you can easily create this by implementing your own delegate to style your top-level items in your tree. [/quote]
          i dont know what you mean , can u explain more ?

          [quote author="Adrien Leravat" date="1359032023"]I would say that's more like multiple QTreeWidget in a QVBoxLayout (at least easier to do)

          @Code_ReaQtor: Also true, but without visible sections.[/quote]

          yes create this but how i can manage selected items and click events on them ?

          ty for your answers

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Adrien Leravat
            wrote on last edited by
            #6

            As QTreeWidget is based on QTreeView (A view of the Model-View-Delegate implemented in Qt), you can use the selectionModel method on you QTreeWidget to retrieve the instance of QItemSelectionModel used.

            The "QItemSelectionModel ":http://doc.qt.digia.com/qt/qitemselectionmodel.html#signals instance returned have signals that are emitted when selection change (i.e. user selected an item in you QTreeWidget).

            Connect a slot to the wanted signal emitted by QItemSelectionModel to handle them.

            Adeneo Embedded - www.adeneo-embedded.com

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #7

              Take a look at [[doc:QStyledItemDelegate]]. You can subclass it and implement your own rendering for top-level items by reimplementing sizeHint and paint. The index that you get can be easily queried to see if you're dealing with a top-level item (those items have an invalid parent()) and if the item is not the first item (check against row 0).

              For all top level items (except the one at row 0), you simply return a bigger size hint to make space for the line, and in the paint event, you render the line and under that the item itself, re-using the existing implementation for that. For all other items, you simply return whatever the base class implementation does.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bepehr
                wrote on last edited by
                #8

                [quote author="Andre" date="1359035280"]Take a look at [[doc:QStyledItemDelegate]]. You can subclass it and implement your own rendering for top-level items by reimplementing sizeHint and paint. The index that you get can be easily queried to see if you're dealing with a top-level item (those items have an invalid parent()) and if the item is not the first item (check against row 0).

                For all top level items (except the one at row 0), you simply return a bigger size hint to make space for the line, and in the paint event, you render the line and under that the item itself, re-using the existing implementation for that. For all other items, you simply return whatever the base class implementation does. [/quote]

                ty its a good way , but i cant make space between items by size Hint because it make item bigger , look at picture you will know what i mean
                how i can find where painter must draw item ? for drawing line ...
                !http://ma3ta.persiangig.com/pic/2.png(size hint problem)!

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #9

                  That the item becomes bigger is good: you need the space to draw your line. You are not really making space between the items this way, you're just extending the item and making it look like you inserted a separator line.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bepehr
                    wrote on last edited by
                    #10

                    [quote author="Andre" date="1359110800"]That the item becomes bigger is good: you need the space to draw your line. You are not really making space between the items this way, you're just extending the item and making it look like you inserted a separator line. [/quote]

                    yes i know bigger item is good , but problem is this border of item , how can i keep border and item shape like normal items ? and how i can get that item X and Y to draw a line ?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #11

                      What did you try already? You're not expecting a ready-made solution I hope?

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        bepehr
                        wrote on last edited by
                        #12

                        [quote author="Andre" date="1359117433"]What did you try already? You're not expecting a ready-made solution I hope?[/quote]

                        ty you Andre for your help , i have done this by reimplementing sizeHint and paint and change option.rect
                        its a pic of result
                        !http://ma3ta.persiangig.com/pic/tree2.png(result)!

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #13

                          Looks fine to me. Any issues left?

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            bepehr
                            wrote on last edited by
                            #14

                            [quote author="Andre" date="1359363623"]Looks fine to me. Any issues left? [/quote]

                            yes i have one more problem , for each item text and icon location is fine but i want to draw border from x=0 , like this red border in this picture , maybe i can draw item from x=0 and add padding-left to item for icon and text but i do not support this .. , i just must change in paint of this item
                            any better idea ?

                            !http://ma3ta.persiangig.com/pic/tree3.png(border)!

                            ty ..

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #15

                              I don't think the standard highlights are rendered there either in a tree view. You might have to tweak the rect of the option you get, but I did not try this myself.

                              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