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 change just one item of QCombobox editable by the user
Forum Updated to NodeBB v4.3 + New Features

How to change just one item of QCombobox editable by the user

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qcombobox
4 Posts 2 Posters 2.0k 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.
  • L Offline
    L Offline
    learnist
    wrote on 26 Jun 2020, 19:41 last edited by learnist
    #1

    i have 4 items in my QCombobox,

    'Bryce king'
    'James White'
    'Russo W'
    'Custom Manager'
    

    so when i click on

    'Custom Manager',
    

    it should change to editable and i must be able to enter my own desired name.

    i have tried to achieve this behavior using Qtcreator, and in the properties, i can set it to editable but that would make all items editable instead of just 1.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 26 Jun 2020, 20:06 last edited by mrjj
      #2

      Hi
      Editable is for all items then.
      It cant handle only one being editable as its not the design.

      The normal use case for this would be to have it nonedible and then have

      'Add Custom Manager'

      Then when you select that, it shows a QInputDialog allowing users to enter a name and press ok to have that added to the listed and selected as the current one.

      That said something like this does work ok-ish

      void MainWindow::on_comboBox_currentIndexChanged(int index)
      {
          if (index == ui->comboBox->count()-1)
              ui->comboBox->setEditable(true);
          else
              ui->comboBox->setEditable(false);
      }
      
      L 1 Reply Last reply 26 Jun 2020, 20:21
      2
      • M mrjj
        26 Jun 2020, 20:06

        Hi
        Editable is for all items then.
        It cant handle only one being editable as its not the design.

        The normal use case for this would be to have it nonedible and then have

        'Add Custom Manager'

        Then when you select that, it shows a QInputDialog allowing users to enter a name and press ok to have that added to the listed and selected as the current one.

        That said something like this does work ok-ish

        void MainWindow::on_comboBox_currentIndexChanged(int index)
        {
            if (index == ui->comboBox->count()-1)
                ui->comboBox->setEditable(true);
            else
                ui->comboBox->setEditable(false);
        }
        
        L Offline
        L Offline
        learnist
        wrote on 26 Jun 2020, 20:21 last edited by
        #3

        @mrjj Thanks So much !!

        M 1 Reply Last reply 26 Jun 2020, 20:29
        0
        • L learnist
          26 Jun 2020, 20:21

          @mrjj Thanks So much !!

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 26 Jun 2020, 20:29 last edited by
          #4

          @learnist
          Np :)
          However, for a real app, you should also consider the use case where users spell the new name
          wrong and want to delete it/edit it later to correct it.

          1 Reply Last reply
          0

          2/4

          26 Jun 2020, 20:06

          • Login

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