Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-95241

add QListWidget::currentText() method

    XMLWordPrintable

Details

    • Task
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • None
    • Widgets: Itemviews
    • None

    Description

      QListWidget class seems to be missing an easy way to get the current text. We can get the current text by using listWidget->currentItem().text() but this requires checking for nullpltr and if this check is forgotten, it can be a problem. Especially for beginners who often forget these checks. And as I believe QListWidget is intended for simple code with simple usage and so beginners use it very often. True professionals use QListView with their own handcrafted list models of course

      It is also lacking API consistency a bit. We already have signal currentTextChanged(QString) but not currentText() method. I believe there should be a duality among these signals and getter methods. Similar to existing currentRowChanged() signal and currentRow() method.

      Obvious solution would be to add QString QListWidget::currentText() const method. When there si no current item selected, then it should return null QString. This will lead to simpler and more robust code in many cases. Therefore the usage will be safe because no nullptr checks are necessary. I think that adding this method should be a no-brainer since this will not break existing code in any way.

      People sometimes use QListWidget as almost a drop-in replacement for QComboBox when they find combo box in not what they need. And there is QComboBox::currentText() method. So if we add this method also to QListWidget, the users will not need to change their code if they replace QComboBox with QListWidget.

      Note: for the sake complete consistency, setter method setCurrentText(QString) would also be handy. It shoudl behave the same as QComboBox::setCurrentText().

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes