Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Separate display text for Selected Item for QComboBox
Qt 6.11 is out! See what's new in the release blog

Separate display text for Selected Item for QComboBox

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 3.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ajaxcrypto
    wrote on last edited by
    #1

    In a QComboBox I have a set of QString. The standard behavior is that whatever entry is selected gets displayed at top (QLineEdit). However my need is to display a modified version of the selected text in the line edit without changing the text in the drop down list. How can I go about achieving this?

    e.g. If the list has { "a", "b", "c" }, selecting "a" , the line edit should contain "a-1".

    jsulmJ Venkatesh VV 2 Replies Last reply
    0
    • A ajaxcrypto

      In a QComboBox I have a set of QString. The standard behavior is that whatever entry is selected gets displayed at top (QLineEdit). However my need is to display a modified version of the selected text in the line edit without changing the text in the drop down list. How can I go about achieving this?

      e.g. If the list has { "a", "b", "c" }, selecting "a" , the line edit should contain "a-1".

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ajaxcrypto Using http://doc.qt.io/qt-5/qcombobox.html#lineEdit you can get the line edit and then change its text using http://doc.qt.io/qt-5/qlineedit.html#text-prop

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • A ajaxcrypto

        In a QComboBox I have a set of QString. The standard behavior is that whatever entry is selected gets displayed at top (QLineEdit). However my need is to display a modified version of the selected text in the line edit without changing the text in the drop down list. How can I go about achieving this?

        e.g. If the list has { "a", "b", "c" }, selecting "a" , the line edit should contain "a-1".

        Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by Venkatesh V
        #3

        @ajaxcrypto
        Hi,

        Once you select item, activated(int index) signal will be emitted connect the signal to some slot.

        // in slot do like this
        void onActivated(int index)
        {
        QString LineEditStr =ComboBox.itemText(index).append("-").append(QString::number(index+1));

        LineEdit.setText(LineEditStr);

        }

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ajaxcrypto
          wrote on last edited by
          #4

          Thank you for pointing me in the right direction. I styled the Line edit accordingly and displaying a modified selected item text.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved