Results 1 to 3 of 3

Thread: How do I remove the inverted background on selected item in QListView

  1. #1
    Join Date
    Oct 2012
    Posts
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Cool How do I remove the inverted background on selected item in QListView

    I have a dialog with a set of radio buttons and a QListView.

    The ui behavior that I'm trying to get is:
    1. If user selects/activates an item in the QListViewthe the radio buttons should be unchecked.
    2. If user checks a radio button, the selection should be cleared in the QListView.

    I have gotten the behaviour I want by sub-classing QListView and implementing void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselecte). This allows me to uncheck the radio buttons when an item is selected. When a radio button is checked by the user, I use QListView::clearSelection() to clear the selection. It works great.

    However there is a visual issue. When the user selects an item either with the mouse or using tab and keystrokes, the background of the row containing the item is inverted. QListView::clearSelection() removes the selection but leaves the background of the row inverted. This might be confusing to the user. How to a restore the background of the item row so that it is not inverted.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I remove the inverted background on selected item in QListView

    Can you provide a screenshot of what you mean?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    16
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How do I remove the inverted background on selected item in QListView

    Here are some screen shots. In the process of taking the screen shots, I may have discovered the solution.
    "initial dialog.png" This screen shot shows the dialog box after initial "show". Nothing is selected.
    IntialDialog.png
    item selected.png This screen shot shows the dialog with radio button unchecked and an item selected in QListView with its background inverted.
    Item Selected.png
    If the user then clicks on radio button or tabs to radio button and checks it with a keystroke The selection is cleared, (I know this because if I fetch the selection list its empty), but the background on the QListView item stays inverted.

    What I discovered in the process of trying to get a screen shot of this last state (radio button checked and non-selected item with inverted background) was that I couldn't get a screen shot
    of it. It appears that when the screen capture tool takes focus it forces some or all of the dialog to repaint and the repaint removes the inverted background. I also discovered that if I cover the dialog
    with another window when dialog is uncovered the inverted background is cleared. So I'm guessing that QListView::selectionClear() clears that selection, as I wanted, but doesn't remove the inverted background.Ssomehow I have t force a repaint. Its confusing because I can use the tab key to move around to different widgets on the dialog and the inverted background remains. I would have thought that tabbing or clicking between widgets after the state change with QListView:: selectionClear() would have triggered the required repaint.

    So I'd appreciate any hints you can give me ZenMaster. In the mean time I'll trying "dirtying" parts of the dialog and calling repaint on the dialog and or QListView objects to see if that does the trick. Given all the optimizations in windowing systems I'm guessing that unless I can convince the Window system that the QListView is dirty, just calling repaint won't do anything.


    Added after 22 minutes:


    Problem solved. Trying to get the screen shot Master of Zen requested put me on the track.
    The solution is:
    1) Save the QModelIndex of the selected row (if there is one)
    2) Call QListView::selectionClear() to clear the selection.
    3) Call QListView::update(const QModelIndex) using saved row index.
    The update immediately clears the inverted background.
    Last edited by cqubed; 12th December 2012 at 03:40.

Similar Threads

  1. Replies: 14
    Last Post: 2nd October 2012, 04:10
  2. Draw line with inverted background color
    By viswanath in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2011, 04:57
  3. QListView (QT4.7): How can i get the selected Item
    By rafikingkong in forum Newbie
    Replies: 2
    Last Post: 2nd June 2011, 19:58
  4. QListview set selected item
    By Freeman551 in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2009, 01:17
  5. QHeaderView: background of selected header item with CSS
    By antarctic in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2009, 08:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.