Search code examples
c++qtmodel-view-controllerqabstractitemview

Item is selected but isn't highlighted


I work with Qt/C++, and I have a QListView to display icons on screen. I set the QListView::iconMode to display it as icon view. But I cannot see that it is selected(but it is selected) it doesn't highlights. However it works for list mode. I have this.

listView->setSelectionMode(QListView::SingleSelection);
listView->setSelectionBehavior(QListView::SelectRows);

listView->setFlow(QListView::LeftToRight);
listView->setViewMode(QListView::IconMode);
listView->setWrapping(true);

can you help me?


Solution

  • Documentation of selection rectangle:

    This property holds if the selection rectangle should be visible.

    If this property is true then the selection rectangle is visible; otherwise it will be hidden.

    Note: The selection rectangle will only be visible if the selection mode is in a mode where more than one item can be selected; i.e., it will not draw a selection rectangle if the selection mode is QAbstractItemView::SingleSelection.

    By default, this property is false.

    You have to try either:

    • Manually set the property to true and see if it changes
    • Drop the single selection mode. It is compulsory? Does QAbstractItemView::ContiguousSelection suits your needs?