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

Add icons to ComboBox

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.12.0
    • Quick: Controls 2
    • None
    • Qt 5.12 on Linux

    Description

      It should be possible to add icons to ComboBox controls and the item delegates within, just like can be done with Qt Widgets QComboBox, without having to adjust the contentItem or itemDelegate.

      API-wise I suggest something similar to how currentText and textRole behaves. textRole should perhaps default to DecorationRole. A displayIcon property would default to whatever icon is assigned to the current item but can also be overridden to show a custom icon or show a static icon independent from the current item.

      The difficulty lies in how to interface the QIcon-based DecorationRole of a model with QtQuick / QtQuick Controls Icon, and also how to make icons possible in models in a purely declarative way (both as JS Array and ListModel).

      API examples

      A ComboBox which contains entries with icons and takes whatever icon the currently selected item has (icon API also purely fictional)

      QQC2.ComboBox {
          textRole: "label"
          iconRole: "icon"
          model: [
              {label: "None", icon: "dialog-cancel"},
              {label: "All", icon: Qt.icon("qrc:/icons/all.png"}
          ]
      }

       

      A ComboBox which shows only a static icon independent of the current item

      QQC2.ComboBox {
          displayIcon.name: "view-filter"
          model: ["All Schemes", "Light Schemes", "Dark Schemes"]
      }
      

       

      A ComboBox which has a custom dynamic icon based on the current item

      QQC2.ComboBox {
          textRole: "label"
          iconRole: "icon"
          displayIcon.name: currentIcon.name + "-symbolic"
          model: [
              {label: qsTr("Red"), color: "red", icon: "note-red"},
              {label: qsTr("Green"), color: "green", icon: "note-green"},
              ...
          ]
      }

       

      Usecases for icons on ComboBoxes include (but are not limited to): indicating "orientation", application icons (e.g. chosing a default application or handler), country flags in locale settings.

      Attachments

        Issue Links

          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
              broulik Kai Uwe Broulik
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes