Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get the row-index when click pushbutton in qtablewidget ?



  • 0_1546484061082_QQ截图20190103105410.png

    QPushButton* TableWidget::createSettingBtn()
    {
        QPushButton* btn = new QPushButton(tr("Settings"));
        btn->setStyleSheet("margin-left: 6px; margin-right: 6px; margin-top: 2px; margin-bottom: 2px;");
        
        return btn;
    }
    
    ...
    
    setCellWidget(0, 3, createSettingBtn());
    
    ...
    

    When click Setting pushbutton, I will exec the corresponding settingDialog( I use QList to manage all settingDialogs ).

    So, before I exec the settingDialog, I must get the row-index according to the clicked pushbutton. So I use QTableWidget::currentRow() to get the row-index, but it failed, because when I firstly exec the program and click the pushbutton, QTableWidget::currentRow() will return -1.

    And then , I use QTableWidget's signals to get the row-index, such as cellActivated(int row, int column) etc..., but all failed.

    So, How to get the row-index when click pushbutton in qtablewidget? Thanks in advance.



  • @Limer

    You can make use of QSignalMapper http://doc.qt.io/qt-5/qsignalmapper.html#details


Log in to reply