How to delete a row of Tablewidget ? If Delete button has been added using code .
-
I am fetching data from data base and adding Delete button in every row using below code .
for ( int k = 0; k <3 ; k++) {
QPushButton *btn = new QPushButton(ui->TableWidget);
ui->TableWidget->setCellWidget(k,2,btn);
btn->setText("Delete");}I want to delete specific row in Tablewidget how can I do it ?
I have three columns in Table widget like this -> Serial Number role Buttons
1 user Delete
2 admin Delete
3 operator Delete -
I am fetching data from data base and adding Delete button in every row using below code .
for ( int k = 0; k <3 ; k++) {
QPushButton *btn = new QPushButton(ui->TableWidget);
ui->TableWidget->setCellWidget(k,2,btn);
btn->setText("Delete");}I want to delete specific row in Tablewidget how can I do it ?
I have three columns in Table widget like this -> Serial Number role Buttons
1 user Delete
2 admin Delete
3 operator Delete@Pappu-Kumar-Keshari
You are not really supposed to usesetCellWidget()for all these buttons, you're supposed to useQStyledItemDelegates. But @VRonin no longer seems to frequent this forum :(You need somehow to identify which row each button is associated with when you get the
clicked()signal. 3 ways:-
You will have to get the
QPushButtonsignaller and find which row it is on in the table widget. -
When you
connect()each button you are creating use a lambda for the slot, to which you pass an extra parameter of the row number. -
An alternative to #2 is to use QButtonGroup Class for each column of buttons. Use its
setId()to associate the row number, which will be passed by theidClicked()signal. This is the one I would do, for neatness.
-
-
how about hide, instead of delete?
-
how about hide, instead of delete?
@micha_eleric
Hide what, instead of delete? The OP is asking a common question about how to have a button against each row, to delete that row from the database, or similar functionality.