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. How to set QComboBox item data from QtDesigner
Forum Updated to NodeBB v4.3 + New Features

How to set QComboBox item data from QtDesigner

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.8k Views 1 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I'm able to add an item from code specifying the user data value:

    void QComboBox::addItem(const QString &text, const QVariant &userData = QVariant())
    

    But how to do the same using the build-in editor of QtDesigner?

    28adba10-0111-48da-984d-43ad4360e442-immagine.png

    I don't see any related property.

    Christian EhrlicherC 1 Reply Last reply
    0
    • M Mark81

      I'm able to add an item from code specifying the user data value:

      void QComboBox::addItem(const QString &text, const QVariant &userData = QVariant())
      

      But how to do the same using the build-in editor of QtDesigner?

      28adba10-0111-48da-984d-43ad4360e442-immagine.png

      I don't see any related property.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 Double click on the QComboBox

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @Mark81 Double click on the QComboBox

        M Offline
        M Offline
        Mark81
        wrote on last edited by Mark81
        #3

        @Christian-Ehrlicher Are you sure? If I double click it opens the very same window I've already pasted above. But still I don't understand how to set the user data (not the text, of course).

        JonBJ Christian EhrlicherC 2 Replies Last reply
        0
        • M Mark81

          @Christian-Ehrlicher Are you sure? If I double click it opens the very same window I've already pasted above. But still I don't understand how to set the user data (not the text, of course).

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Mark81
          I do not see that you can associate data with items in Designer. So far as I can see, only from code. For one thing, the data is of any QVariant type, so it's not clear what a design-time editor would have to do to support that. You are perhaps assuming you would associate text, but it does not have to be, could be arbitrary binary data.

          M 1 Reply Last reply
          1
          • JonBJ JonB

            @Mark81
            I do not see that you can associate data with items in Designer. So far as I can see, only from code. For one thing, the data is of any QVariant type, so it's not clear what a design-time editor would have to do to support that. You are perhaps assuming you would associate text, but it does not have to be, could be arbitrary binary data.

            M Offline
            M Offline
            Mark81
            wrote on last edited by Mark81
            #5

            @JonB ok, I got it. It's a good point, but from my point of view they could be add just the most common types: QString, int, double, etc... Of course if one needs a very specific type he has to do in code.

            JonBJ 1 Reply Last reply
            1
            • M Mark81

              @Christian-Ehrlicher Are you sure? If I double click it opens the very same window I've already pasted above. But still I don't understand how to set the user data (not the text, of course).

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Mark81 said in How to set QComboBox item data from QtDesigner:

              If I double click it opens the very same window

              You should double click on the QComboBox you put into your QWidget. Then an editor shows up where you can enter some strings.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              M 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @Mark81 said in How to set QComboBox item data from QtDesigner:

                If I double click it opens the very same window

                You should double click on the QComboBox you put into your QWidget. Then an editor shows up where you can enter some strings.

                M Offline
                M Offline
                Mark81
                wrote on last edited by
                #7

                @Christian-Ehrlicher yes, it is what I did. I can enter the text strings, but not the user data values. If I'm wrong, please attach a screenshot where you can show you are able to enter both.

                Christian EhrlicherC 1 Reply Last reply
                0
                • M Mark81

                  @Christian-Ehrlicher yes, it is what I did. I can enter the text strings, but not the user data values. If I'm wrong, please attach a screenshot where you can show you are able to enter both.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Mark81 You are correct. This is to complicated. But feel free to provide a patch.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • M Mark81

                    @JonB ok, I got it. It's a good point, but from my point of view they could be add just the most common types: QString, int, double, etc... Of course if one needs a very specific type he has to do in code.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @Mark81 said in How to set QComboBox item data from QtDesigner:

                    they could be add just the most common types: QString, int, double, etc...

                    Well, they don't offer that... :)

                    If I were in a situation where I really wanted to add data field at design-time so I could do it in one place associated with where I did text, and if I wanted to add strings (or maybe numbers) for the data. I would do something like: put # followed by data value after text in Designer. Like Off#0 or This is long text#long. And then at UI setup time walk my combo's text items and separate them out to reset text and the data on the #. Yes it's ugly, but I might if I wanted the data specified at design-time.

                    1 Reply Last reply
                    1

                    • Login

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