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. How to get the row-index when click pushbutton in qtablewidget ?

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

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 787 Views
  • 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by Limer
    #1

    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.

    RatzzR 1 Reply Last reply
    0
    • LimerL 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.

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by
      #2

      @Limer

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

      --Alles ist gut.

      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