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. How to use style sheet in qt to not to change row color on selection.

How to use style sheet in qt to not to change row color on selection.

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 6 Posters 4.1k 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.
  • JonBJ JonB

    @tushu
    What do you not understand? @Bonnie wrote a comment against the line for you:

    //make sure no item is flaged as selected when drawing rows

    Isn't that what you have been asking for?

    T Offline
    T Offline
    tushu
    wrote on last edited by
    #21

    @JonB
    What I understood : When I will click on any row, it will get selected and this method will get invoke. And then , thorugh this method , I will deselect my current selection by clearing bits and calling that method again. So in the end, there will not be any selection. So no dark blue default selection of row by Qt.

    Sorry if my understanding is wrong.

    JonBJ 1 Reply Last reply
    0
    • T tushu

      @JonB
      What I understood : When I will click on any row, it will get selected and this method will get invoke. And then , thorugh this method , I will deselect my current selection by clearing bits and calling that method again. So in the end, there will not be any selection. So no dark blue default selection of row by Qt.

      Sorry if my understanding is wrong.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #22

      @tushu
      Well that is about right. Certainly the end result should indeed be "So no dark blue default selection of row by Qt."

      But "and calling that method again." does not happen. When the paint() is called by Qt to draw the item, on entry QStyleOptionViewItem *option contains various options directing how to draw it. Among these is a bit for whether the item is selected, and the base paint will act on that by showing the item in blue or whatever.

      @Bonnie has given you an override for the initStyleOption(), whose job it is to process those options for the forthcoming paint. His override removes any State_Selected bit in the option flags, and only after that calls the base QStyledItemDelegate::initStyleOption(option, index). So that will simply not see that the item was selected/had the draw-as-selected bit set. So it will set up for the paint to draw as though the item is not selected.

      Note that this does not affect that the item actually is selected as far as the rest of your or Qt code is concerned. It will stay selected (or unselected). Ut simply will not paint it to show it is selected.

      T 1 Reply Last reply
      0
      • JonBJ JonB

        @tushu
        Well that is about right. Certainly the end result should indeed be "So no dark blue default selection of row by Qt."

        But "and calling that method again." does not happen. When the paint() is called by Qt to draw the item, on entry QStyleOptionViewItem *option contains various options directing how to draw it. Among these is a bit for whether the item is selected, and the base paint will act on that by showing the item in blue or whatever.

        @Bonnie has given you an override for the initStyleOption(), whose job it is to process those options for the forthcoming paint. His override removes any State_Selected bit in the option flags, and only after that calls the base QStyledItemDelegate::initStyleOption(option, index). So that will simply not see that the item was selected/had the draw-as-selected bit set. So it will set up for the paint to draw as though the item is not selected.

        Note that this does not affect that the item actually is selected as far as the rest of your or Qt code is concerned. It will stay selected (or unselected). Ut simply will not paint it to show it is selected.

        T Offline
        T Offline
        tushu
        wrote on last edited by
        #23

        @JonB
        Now I understood. Before this also I had used this bit clearing. But did not get why was it for. Now I understood.
        Thanks for your explanation.

        I am feeling confident in Qt because of this forum and the good people like you all, who always helped me.
        Thanks a lot once again. :)

        1 Reply Last reply
        0
        • T tushu

          @Bonnie Perfect solution. It worked perfectly.

          But I got suggestion over the output.
          Current output is :

          sbela.PNG

          Clicked row ( add_7 ) is originally without color ( white ) . But after click, it slightly becoming bluish. Can we remove that light blue color ?

          sela11.PNG

          2nd row is clicked.

          But when I click on a coloured row, it looks fine.

          Is there any way to remove that light blue color when I click on non coloured row ?

          And many thanks for your efforts and perfect Solution.

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #24

          @tushu Well, as I said, the light blue color is the focus frame, it indicates the current index of the view.
          The simpliest way is just disable all the indexes in the row if you don't have any interactive operation upon them, so they can't be set to be the current index.
          (If there is any interactive operation, then I can't understand why it need to be removed...)
          Since you're using QTreeWidget, you can call QTreeWidgetItem::setDisabled.
          Note that will make the item's text gray if no foreground color is set

          1 Reply Last reply
          1

          • Login

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