Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    4
    932
    Loading More Posts
    • 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.
    • Ratzz
      Ratzz last edited by Ratzz

      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 Reply Quote 0
      • Igor Y
        Igor Y last edited by Igor Y

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

        Ratzz 1 Reply Last reply Reply Quote 0
        • Ratzz
          Ratzz @Igor Y last edited by

          @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.

          Ratzz 1 Reply Last reply Reply Quote 0
          • Ratzz
            Ratzz @Ratzz last edited by

            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 Reply Quote 0
            • First post
              Last post