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. previously selected item in QListView retains light blue background as long as mouse is over app
Qt 6.11 is out! See what's new in the release blog

previously selected item in QListView retains light blue background as long as mouse is over app

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 298 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.
  • J Offline
    J Offline
    Joachim W
    wrote on last edited by
    #1

    After adding and selecting a new item in a QListView, the new item receives dark blue background as it should, but the background of the previously selected item goes from dark blue to light blue whereas I need and expect it to go to white. Remarkably, it does go to white if the mouse pointer is taken away from the Qt app (which prevents me from taking a screenshot).

    To add and select the new item, I do in the model

        beginInsertRows({}, row, row);
        // append new item to list model
        endInsertRows();
        emit ListChanged();
    

    and in the list view constructor, I did something like

        connect(model, &Model::ListChanged, [this] {
            selectionModel()->clearSelection();
            selectionModel()->select(model->index(model->currentIndex(), 0),
                                     QItemSelectionModel::Select);
        });
    

    It all works except for the weird light blue background. I have no clue where it originates.

    I removed my entire stylesheet - the dark and light blue backgrounds stay.

    Chris KawaC 1 Reply Last reply
    0
    • J Joachim W

      After adding and selecting a new item in a QListView, the new item receives dark blue background as it should, but the background of the previously selected item goes from dark blue to light blue whereas I need and expect it to go to white. Remarkably, it does go to white if the mouse pointer is taken away from the Qt app (which prevents me from taking a screenshot).

      To add and select the new item, I do in the model

          beginInsertRows({}, row, row);
          // append new item to list model
          endInsertRows();
          emit ListChanged();
      

      and in the list view constructor, I did something like

          connect(model, &Model::ListChanged, [this] {
              selectionModel()->clearSelection();
              selectionModel()->select(model->index(model->currentIndex(), 0),
                                       QItemSelectionModel::Select);
          });
      

      It all works except for the weird light blue background. I have no clue where it originates.

      I removed my entire stylesheet - the dark and light blue backgrounds stay.

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      @Joachim-W It's probably the highlight of the current item. Yes, current item and selection are not the same thing. Try adding QItemSelectionModel::Current to your select call to also change the current item.
      Also, you don't need to separate clearing and selection, you can just use QItemSelectionModel::ClearAndSelect to do both in one call.

      1 Reply Last reply
      1
      • J Joachim W has marked this topic as solved on
      • J Joachim W referenced this topic on
      • Pl45m4P Pl45m4 referenced this topic on

      • Login

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