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. QComboBox addin dummy placeholder
Forum Updated to NodeBB v4.3 + New Features

QComboBox addin dummy placeholder

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 7 Posters 6.5k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi
    You can try
    ui->comboBox->setEditable(true);
    ui->comboBox->setCurrentIndex(-1);
    ui->comboBox->setCurrentText("DUMMY TEXT");

    it will then show dummy text until user selects something.

    ZgemboZ 1 Reply Last reply
    3
    • ZgemboZ Zgembo

      Hi all,

      I have been searching for a while, a way to add dummy item into my combo box but without any luck. I have an combo box and I would like to add a place holder text like "Select Year" as a default first item. Does anyone have any examples of this?

      Tnx

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

      @Zgembo
      You could use @mrjj's suggestion (though making it setEditable(true) if it's not in the first place is not a good idea), or you could tell us whether your combobox is editable or not for alternatives....

      1 Reply Last reply
      1
      • A.A.SEZENA Offline
        A.A.SEZENA Offline
        A.A.SEZEN
        wrote on last edited by
        #4

        Another way...
        Your comboBox is editable
        ui->comboBox->lineEdit()->setPlaceholderText("Text");

        JonBJ 1 Reply Last reply
        2
        • A.A.SEZENA A.A.SEZEN

          Another way...
          Your comboBox is editable
          ui->comboBox->lineEdit()->setPlaceholderText("Text");

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

          @A.A.SEZEN Indeed, which is why we need to know whether OP's combobox is editable or not.

          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            You can try
            ui->comboBox->setEditable(true);
            ui->comboBox->setCurrentIndex(-1);
            ui->comboBox->setCurrentText("DUMMY TEXT");

            it will then show dummy text until user selects something.

            ZgemboZ Offline
            ZgemboZ Offline
            Zgembo
            wrote on last edited by
            #6

            @mrjj Thank you. It works.

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              Hi
              ok super. make sure to also try @A.A.SEZEN suggestions
              ui->comboBox->setEditable(true);
              ui->comboBox->lineEdit()->setPlaceholderText("Text");
              as thats a real text place holder :)

              1 Reply Last reply
              4
              • D Offline
                D Offline
                Dosart
                wrote on last edited by
                #8

                How I can change color in place holder?

                Pl45m4P mrjjM 2 Replies Last reply
                0
                • D Dosart

                  How I can change color in place holder?

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #9

                  @Dosart

                  I dont know if you can. Placeholder texts are always gray

                  • https://doc.qt.io/qt-5/qlineedit.html#placeholderText-prop

                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  3
                  • D Dosart

                    How I can change color in place holder?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Dosart

                    Hi
                    Depending on platform. this might work

                        QPalette pal = ui->lineEdit->palette();
                        pal.setColor(QPalette::ColorRole::PlaceholderText, QColor( 255,0,0));
                        ui->lineEdit->setPalette(pal);
                    
                    

                    Does on Win 10. Not tested anything else.

                    1 Reply Last reply
                    2
                    • D Offline
                      D Offline
                      DizzyDwarf
                      wrote on last edited by
                      #11

                      worked for me:

                          self.name_dropdown.placeholderText()
                          self.name_dropdown.setPlaceholderText('Choose Operator')
                          self.name_dropdown.addItems(['Name1, 'Name2', 'Name3'])
                      
                      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