Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    2
    2
    433
    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.
    • Limer
      Limer last edited by Limer

      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.

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

        @Limer

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

        --Alles ist gut.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post