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. Dropdown in Qtableview

Dropdown in Qtableview

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 4.8k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #3

    Hi,

    So you want to have an editable QComboBox in a specific cell ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    N 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      So you want to have an editable QComboBox in a specific cell ?

      N Offline
      N Offline
      n-2204
      wrote on last edited by n-2204
      #4

      @SGaist

      I want a dropdown in a QTableview cell, drop down has 2 values like a and b,  if user selects a then that is editable, but if b then non editable.                
                  
      When user selects a from drop down the cell content should set as a and user can edit that cell (Qtableview cell ) value, but if user selects b then cell is not editable.
      
      JonBJ 1 Reply Last reply
      0
      • N n-2204

        @SGaist

        I want a dropdown in a QTableview cell, drop down has 2 values like a and b,  if user selects a then that is editable, but if b then non editable.                
                    
        When user selects a from drop down the cell content should set as a and user can edit that cell (Qtableview cell ) value, but if user selects b then cell is not editable.
        
        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #5

        @n-2204
        This is not at all clear. (It is also very weird!)

        You want a dropdown to appear in a cell. That dropdown has 2 values, a and b. User can select, by clicking, either value. If user selects b then "nothing special happens". But if user selects a what becomes editable? The a that the user has just selected?? Something else??

        Apart from the fact that it is hard to think of a case for this UI approach, it does not sound like it has anything to do with being in a QTableView cell. Take the combobox outside of the table and design whatever behaviour you say you want, get that working, before you worry about how to put it into a table.

        N 1 Reply Last reply
        0
        • JonBJ JonB

          @n-2204
          This is not at all clear. (It is also very weird!)

          You want a dropdown to appear in a cell. That dropdown has 2 values, a and b. User can select, by clicking, either value. If user selects b then "nothing special happens". But if user selects a what becomes editable? The a that the user has just selected?? Something else??

          Apart from the fact that it is hard to think of a case for this UI approach, it does not sound like it has anything to do with being in a QTableView cell. Take the combobox outside of the table and design whatever behaviour you say you want, get that working, before you worry about how to put it into a table.

          N Offline
          N Offline
          n-2204
          wrote on last edited by
          #6

          @JonB

          Ya, my mistake not mentioned clear. When user select a from drop down the cell content should set as a and user can edit that cell (Qtableview cell ) value, but if user selects b then cell is not editable.
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #7

            Can you explain the workflow of that design ?

            While the "effect" is a bit clearer, as @JonB I fail to see how you want your users to interact with your application ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            N 1 Reply Last reply
            0
            • SGaistS SGaist

              Can you explain the workflow of that design ?

              While the "effect" is a bit clearer, as @JonB I fail to see how you want your users to interact with your application ?

              N Offline
              N Offline
              n-2204
              wrote on last edited by jsulm
              #8

              @SGaist @JonB

              As I mentioned earlier, In a Qtableview cell I want to add a drop down option drop down contains two option like a ,b and basically a ,b, if user selects a then that cell will be editable it user select b then cell will be non editable this m doing for my calculation purpose , like b will have default data but if user want to change then change it to a an edit it.

              If any suggestions plz mention. Thank you

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                And that on one specific cell ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                N 1 Reply Last reply
                0
                • SGaistS SGaist

                  And that on one specific cell ?

                  N Offline
                  N Offline
                  n-2204
                  wrote on last edited by
                  #10

                  @SGaist yes

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    Then why not just position a QComboBox there and hide it once it has been used ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    N 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Then why not just position a QComboBox there and hide it once it has been used ?

                      N Offline
                      N Offline
                      n-2204
                      wrote on last edited by
                      #12

                      @SGaist
                      can you explain more?

                      what I understood is, add a combobox and do the selection like if selected a then edit that to other value and if selected b then set the value to tableview cell and then hide combobox ??

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        Yes, since you only have that one combo box for that unique action.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        N 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Yes, since you only have that one combo box for that unique action.

                          N Offline
                          N Offline
                          n-2204
                          wrote on last edited by
                          #14

                          @SGaist

                          hide the QCombobox how to do that?

                          And one issue when editing the combobox , new value in adding to new index?
                          how can I replace ?

                          jsulmJ 1 Reply Last reply
                          0
                          • N n-2204

                            @SGaist

                            hide the QCombobox how to do that?

                            And one issue when editing the combobox , new value in adding to new index?
                            how can I replace ?

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

                            @n-2204 said in Dropdown in Qtableview:

                            hide the QCombobox how to do that?

                            https://doc.qt.io/qt-5/qwidget.html#hide

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

                            N 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @n-2204 said in Dropdown in Qtableview:

                              hide the QCombobox how to do that?

                              https://doc.qt.io/qt-5/qwidget.html#hide

                              N Offline
                              N Offline
                              n-2204
                              wrote on last edited by
                              #16

                              void QWidget::hide()
                              will hide the combobox from cell, and I have to show user the value of combobox selected by user like if combobox has 2 values when user selects a it is editable user can change it to t and if user selects b then its non editable and this value is set but if use hide then combobox will be hidden ?

                              jsulmJ 1 Reply Last reply
                              0
                              • N n-2204

                                void QWidget::hide()
                                will hide the combobox from cell, and I have to show user the value of combobox selected by user like if combobox has 2 values when user selects a it is editable user can change it to t and if user selects b then its non editable and this value is set but if use hide then combobox will be hidden ?

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

                                @n-2204 said in Dropdown in Qtableview:

                                if user selects b then its non editable and this value is set but if use hide then combobox will be hidden ?

                                Then show the selected value in a QLabel

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

                                N 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @n-2204 said in Dropdown in Qtableview:

                                  if user selects b then its non editable and this value is set but if use hide then combobox will be hidden ?

                                  Then show the selected value in a QLabel

                                  N Offline
                                  N Offline
                                  n-2204
                                  wrote on last edited by n-2204
                                  #18

                                  how to replace value in combobox?

                                    testdropdown::testdropdown(QWidget *parent)
                                  : QMainWindow(parent)
                                   {
                                  ui.setupUi(this);
                                  
                                  QStandardItemModel* stndrditem_model1 = NULL;
                                  QComboBox* combobox1;
                                  QStringList lst;
                                  
                                  if (stndrditem_model1 == NULL) {
                                      stndrditem_model1 = new QStandardItemModel(10, 11, this);//row*col
                                  }
                                  
                                  ui.tableView->setModel(stndrditem_model1);
                                  ui.tableView->setColumnWidth(2, 1);
                                  
                                  const QModelIndex idx = stndrditem_model1 ->index(1, 1);
                                  combobox1 = qobject_cast<QComboBox*>(ui.tableView->indexWidget(idx));
                                   if (!combobox1) {
                                       combobox1 = new QComboBox();
                                       ui.tableView->setIndexWidget(idx, combobox1);
                                   }
                                  
                                   lst<< "test" << "testdata";
                                   combobox1->addItems(lst);
                                   connect(combobox1, 
                                  QOverload<int>::of(&QComboBox::currentIndexChanged), this, &testdropdown::testedit);
                                  
                                   }
                                    void testdropdown::testedit(int indx) {
                                  if (indx == 1) { //when user select testdata
                                      combobox1->setEditable(true);
                                  //when user enter at index 1 the new data added at index 2 I want to replace at same index  
                                      //how to replace testdata string list value with new value in combobox and index should remain same which is entered by user  ??
                                    
                                  }
                                  else{
                                      combobox1->setEditable(false);
                                  }
                                  }
                                  
                                  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