Important: Please read the Qt Code of Conduct -

QCombobox in table widget

  • 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?


  • Hi,

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

  • I don't know what you want to do, but often it is better to use a "QStyledItemDelegate ": for these kind of things. I have written a wiki article "Combo Boxes in Item Views": that demonstrates the principles.

  • Hi
    I have write this:

    QComboBox *combo;
    for (int i=0;i<ui->tableWidget->rowCount();i++){
    combo = new QComboBox;

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

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

  • You can get the sender object by calling "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;
    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.

  • Thanks it works,
    I really need all this combo

    Many Thanks


Log in to reply