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. Add items to combobox depending on another combobox in a tableview set to delegate

Add items to combobox depending on another combobox in a tableview set to delegate

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.2k Views
  • 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.
  • RatzzR Offline
    RatzzR Offline
    Ratzz
    wrote on last edited by Ratzz
    #1

    I am using tableview which is set to custom model implemented using QAbstractTableModel . Also the tableview is set to combobox delegate . How to Add items to combobox in a treeview set to delegate depending on another combobox .
    Suppose i have two colums in a tableview and column 1 has items "A" and "B" . In the column 1 if combobox item is selected to A then item "1" and "2" should be added to combobox of column 2 and if "B" then "1" .

    --Alles ist gut.

    1 Reply Last reply
    0
    • Igor YI Offline
      Igor YI Offline
      Igor Y
      wrote on last edited by Igor Y
      #2

      you can use QAbstractItemDelegate::setEditorData of your delegate to populate items in combo box

      RatzzR 1 Reply Last reply
      0
      • Igor YI Igor Y

        you can use QAbstractItemDelegate::setEditorData of your delegate to populate items in combo box

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on last edited by
        #3

        @Igor-Y
        Thanks for the reply.
        I already have the setEditorData how can i use it to implement this?

        void MyDelegate::setEditorData(QWidget *editor,
                                        const QModelIndex &index) const
        {
                QString value= index.model()->data(index,Qt::DisplayRole).toString();
                QComboBox *comboBox = static_cast<QComboBox*>(editor);
                int itemIndex = comboBox->findText(value);
                comboBox->setCurrentIndex(itemIndex);
        }

        --Alles ist gut.

        RatzzR 1 Reply Last reply
        0
        • RatzzR Ratzz

          @Igor-Y
          Thanks for the reply.
          I already have the setEditorData how can i use it to implement this?

          void MyDelegate::setEditorData(QWidget *editor,
                                          const QModelIndex &index) const
          {
                  QString value= index.model()->data(index,Qt::DisplayRole).toString();
                  QComboBox *comboBox = static_cast<QComboBox*>(editor);
                  int itemIndex = comboBox->findText(value);
                  comboBox->setCurrentIndex(itemIndex);
          }
          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by
          #4

          I was able to get the value of the selected items in the column1 and using it in setEditorData I am adding items to combobox usingaddItems if i get matched selected items from column1

          --Alles ist gut.

          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