Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get QListWidget with focus ?



  • Hi,

    The application that I am developing is based on a tabbed collection of pages. All tab pages are instances of a single widget. In such a widget there are 2 list widgets.

    The problem is that when I select between pages the selection within these list widgets are retained, along with the highlighted items (that is the last selection that was done). How can I get which list widget out of the two has a selected (highligted) item ?



  • Hi,

    This what you mean?

    @QList<QListWidgetItem *> QListWidget::selectedItems() const@



  • No, there are two list widgets on a tab page. When page is selected, one of the list widgets has a highlighted item. User's think that this highlighted item is what has focus, but it is not so (QApplication::focusWidget() does not return either of the 2 list widgets as having focus).

    How do I know which of the 2 list items on the selected page has a highlighted item ? Both return their selected items. Yet only one has a highlighted item.



  • and what if your combine?

    @
    bool QListWidget::hasFocus() const
    QList<QListWidgetItem *> QListWidget::selectedItems() const
    @



  • Maybe you should check focus against QListWidget viewport widget.



  • ah, thought that you're about QListWidget focus check :)


Log in to reply