Qt Forum

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

    Solved How to remove decoration tinting of selected items in item views?

    General and Desktop
    qss views items selection
    4
    10
    2614
    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
      napajejenunedk0 last edited by

      Hello, all.

      By default, on Windows 10 for example, the selected items in item views - QListView, QTableView, QTreeView, etc., are tinted using a semitransparent colored overlay (light blue for instance):
      0_1543225970172_400eb185-0f52-434c-aedb-a4bf5e323051-image.png
      It is configurable using the following QSS *::item:selected { ... } but the problem is that whatever the QSS for this state the tinting of the decoration is left intact (see the white part of the image used for the decoration of the item):
      0_1543226358723_ea5c9baa-feda-47b1-ba7d-1d4e0192830e-image.png

      Is there an integrated way - some QSS statement, to remove or disable the decoration tinting? Presumably, the hard way is to tune some item delegates' painting?

      raven-worx 1 Reply Last reply Reply Quote 1
      • V
        VRonin last edited by

        This is actually some magic that happens inside QIcon. can you show us how you are setting the image for the decoration?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply Reply Quote 0
        • raven-worx
          raven-worx Moderators @napajejenunedk0 last edited by

          @napajejenunedk0
          have you tried the show-decoration-selected property?

          QAbstractItemView {
              show-decoration-selected: 0;
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          N 1 Reply Last reply Reply Quote 1
          • N
            napajejenunedk0 @raven-worx last edited by napajejenunedk0

            @raven-worx, setting it results in resizing the selection marquee to fit the contents horizontally:
            0_1543236217927_4557752e-2b10-4efc-8579-099cf3fbce1f-image.png
            Actually, the name of the QSS property looks promising and targeting exactly this - to remove the tinting of the decoration, but its documentation says exactly what it practically does:

            Controls whether selections in a QListView cover the entire row or just the extent of the text.

            If you have other ideas, they are welcome.

            raven-worx V 2 Replies Last reply Reply Quote 0
            • raven-worx
              raven-worx Moderators @napajejenunedk0 last edited by

              @napajejenunedk0 said in How to remove decoration tinting of selected items in item views?:

              but its documentation says exactly what it practically does:

              Controls whether selections in a QListView cover the entire row or just the extent of the text.

              that doesn't necessarily means the right side of the row. As the name lets one assume.

              Also the corresponding QStyle::SH_ItemView_ShowDecorationSelected doc says:

              When an item in an item view is selected, also highlight the branch or other decoration.

              Can you try to set your model and delegate to a QTreeView and check the results there?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply Reply Quote 0
              • V
                VRonin @napajejenunedk0 last edited by

                @napajejenunedk0 said in How to remove decoration tinting of selected items in item views?:

                If you have other ideas, they are welcome.

                Did you consider my question?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                N 1 Reply Last reply Reply Quote 0
                • N
                  napajejenunedk0 @VRonin last edited by

                  @VRonin, sorry, I thought I provided you with the source code. I haven't found a way to set the decoration through the QSS but only using the standard approach - to pass it from the model. Here is the complete code:

                  QListView* const view = new QListView;
                  QStandardItemModel* const model = new QStandardItemModel( this );
                  model->appendColumn( {
                                           new QStandardItem( QIcon( ":/icon.png" ), "Test 1" ),
                                           new QStandardItem( QIcon( ":/icon.png" ), "Test 2" )
                                       } );
                  view->setModel( model );
                  qApp->setStyleSheet( "QListView::item { outline: none; }"
                                       "QListView::item:selected { background-color: black; color: white; } "
                                       "QListView::item:hover:!selected { background-color: lightgray; color: white; }" );
                  
                  1 Reply Last reply Reply Quote 0
                  • V
                    VRonin last edited by VRonin

                    QIcon uniformIcon(const QString& path){
                        const QPixmap basePixmap(path);
                        QIcon result;
                        for (auto state : {QIcon::Off, QIcon::On}){
                            for (auto mode : {QIcon::Normal, QIcon::Disabled, QIcon::Active, QIcon::Selected})
                                result.addPixmap(basePixmap, mode, state);
                        }
                        return result;
                    }
                    

                    now replace

                    new QStandardItem( QIcon( ":/icon.png" ), "Test 1" ),
                    new QStandardItem( QIcon( ":/icon.png" ), "Test 2" )
                    

                    with

                    new QStandardItem( uniformIcon(QStringLiteral(":/icon.png")), "Test 1" ),
                    new QStandardItem( uniformIcon(QStringLiteral(":/icon.png")), "Test 2" )
                    

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    N 1 Reply Last reply Reply Quote 4
                    • N
                      napajejenunedk0 @VRonin last edited by

                      @VRonin Nice. I was looking for something more integrated, so that to provide clear graphics of the icon all of the time, but obviously the clarity should be achieved in a more manual manner. Thanks. Actually, is there a QSS way to set the decoration?

                      1 Reply Last reply Reply Quote 0
                      • O
                        OSxy last edited by

                        QListView {outline: none;}
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post