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. QCombobox in table widget

QCombobox in table widget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 9.7k 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
    luca72
    wrote on last edited by
    #1

    Hello i have a qcombobox in qtablewidget, i need to get the row (of the tablewidget, not of the combo box) when i click on the combobox but i not able to do it, can you hel me please?

    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      the combo box does not know anything about the table widget. As you are the one, creating and positioning it, store it somewhere.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        I don't know what you want to do, but often it is better to use a "QStyledItemDelegate ":http://doc.qt.nokia.com/latest/qstyleditemdelegate.html for these kind of things. I have written a wiki article "Combo Boxes in Item Views":http://developer.qt.nokia.com/wiki/Combo_Boxes_in_Item_Views that demonstrates the principles.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca72
          wrote on last edited by
          #4

          Hi
          I have write this:

          @
          QComboBox *combo;
          for (int i=0;i<ui->tableWidget->rowCount();i++){
          combo = new QComboBox;
          combo->addItems(lista_combo);
          combo->setObjectName("combo"+QString::number(i));
          connect(combo,SIGNAL(currentIndexChanged(int)),this,SLOT(metto_stringa(int)));
          ui->tableWidget->setCellWidget(i,4,combo);
          }
          ui->tableWidget->resizeColumnsToContents();
          @

          there is a way to pass the combo name so i can get the row number?

          [EDIT: code formatting, please wrap in @-tags, Volker]

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            You can get the sender object by calling "sender() ":http://doc.qt.nokia.com/latest/qobject.html#sender, it returns the sender of the signal that caused the calling of this slot (if there is any). If the slot was not called via signal/slot connection (eg. you can call every slot directly from your code), the method returns a null pointer. So check it!

            In you slot you can do something like this:
            @
            void myClass:fancySlot()
            {
            QObject *s = sender();
            QString senderName;
            if(s)
            senderName = s->objectName();

            // check for set sender name her and process further
            

            }
            @

            But do you really need all the combo boxes in the table at the same time? Or do you need them only to change a value if the user wants to edit the data? If you need the latter, you're better off with the item delegate approach mentioned in my former comment.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca72
              wrote on last edited by
              #6

              Thanks it works,
              I really need all this combo

              Many Thanks

              Luca

              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