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

Setting an editable QComboBox's QLineEdit PlaceholderText should prevent switching the index when items are added

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.15, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6, 6.7, 6.8.0 Beta1
    • None

      The placeholderText property of QComboBox, added in 5.15, has the following documentation:

      "When this function is called before items are added the placeholder text will be shown,... When the QComboBox is editable, use QLineEdit::setPlaceholderText() instead."

      QComboBoxPrivate::rowsInserted, if the current index is invalid, will switch to the first new valid index unless, per the above, the QComboBox placeholderText is set first, in which case it doesn't switch and the placeholder text is still shown. However, if the QComboBox is editable, it doesn't check the placeholderText of the associated QLineEdit. Instead, it switches to the first item when adding items instead of staying displayed on the placeholder text. That's confusing, because the documentation recommends using QLineEdit::setPlaceholderText() instead.

      There is a fairly simple workaround - set the QComboBox placeholderText as well. it can be set to the same thing as the QLineEdit placeholderText (which is fine with implicit sharing), or to anything non-empty. It won't be displayed, it will just be used in that check. So the workaround isn't bad, but it's redundant and the documentation warns against doing it.

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            johnthacker John Thacker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes