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 1.9k 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      2
      • mrjjM mrjj

        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 last edited by
        #3

        @mrjj Thanks So much !!

        mrjjM 1 Reply Last reply
        0
        • L learnist

          @mrjj Thanks So much !!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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

          • Login

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