Hi,
I'm starting with Qt and CPP. Here is my problem : I have a QTableWidget with data and I want to add a button in the first cell of every row to delete the row.
I subclassed the QToolButtonclass and wanted to add as a attribute a pointer to the neighbour cell.
The idea was that the user could delete randomly any row and every deleteRowButton would know its row with neighbourCell->row() (the widget inserted a cell using setItem() can't know the current row, am I right?).
Here is my code :
the creation of the row with the creation of the deleteRowButton, located in my mainwindow (airflowcalculator.cpp) :
tableItem->insertRow(newRow);
tableWidgetEraseItem = new deleteRowButton(*tableWidgetName);
tableItem->setCellWidget(newRow, 0, tableWidgetEraseItem);
tableItem->setItem(newRow, 1, tableWidgetName);
tableItem->insertRow(newRow);
tableWidgetEraseItem = new deleteRowButton(*tableWidgetName);
tableItem->setCellWidget(newRow, 0, tableWidgetEraseItem);
tableWidgetName = new QTableWidgetItem("my name");
tableItem->setItem(newRow, 1, tableWidgetName);
To copy to clipboard, switch view to plain text mode
the slot to remove the row in my mainwindow (airflowcalculator.cpp)
void airflowCalculator::removeAVComponent(int row)
{
tableItem->removeRow(row);
tableItem->selectRow(tableItem->currentRow());
}
void airflowCalculator::removeAVComponent(int row)
{
tableItem->removeRow(row);
tableItem->selectRow(tableItem->currentRow());
}
To copy to clipboard, switch view to plain text mode
The deleteRowButton class (deleterowbutton.cpp)
#include "deleterowbutton.h"
#include <QIcon>
{
neighbourCell = neighbourCellTemp;
setIcon
(QIcon(":/images/delete.png"));
connect(this, SIGNAL(clicked()),this, SLOT(deleteRowSlot()));
}
void deleteRowButton::deleteRowSlot()
{
emit deleteRow(neighbourCell->row());
}
#include "deleterowbutton.h"
#include <QIcon>
deleteRowButton::deleteRowButton(const QTableWidgetItem & neighbourCellTemp)
: QToolButton()
{
neighbourCell = neighbourCellTemp;
setIcon(QIcon(":/images/delete.png"));
connect(this, SIGNAL(clicked()),this, SLOT(deleteRowSlot()));
}
void deleteRowButton::deleteRowSlot()
{
emit deleteRow(neighbourCell->row());
}
To copy to clipboard, switch view to plain text mode
Of course, I suspect the argument passing to the deleteRowButton but I'm a little bit lost after having tried with pointers and references
Thanks in advance!
Bookmarks