View Full Version : Deselecting selection on QTableWidget
grantbj74
25th May 2010, 06:58
Hi,
I would like to deselect what I have currently selected on a QTableWidget. My code goes through and removes some rows from the table. If all rows are removed while a row is selected it crashes. If nothing is selected when everything is removed it doesn't crash.
I have tried the following with no luck:
table->setCurrentCell(-1,-1);
table->clearSelection();
Thanks
Brendan
Lykurg
25th May 2010, 07:03
Please, could you provide a minimal compilable program that reproduce your issue.
grantbj74
25th May 2010, 07:26
It's bit of a mess because I have a pair of vector arrays one for labels on the table another for pointers to endpoints.
You will need to substitute something for TestEndpoint.
std::vector<QLabel*> m_endpoint_labels;
std::vector<TestEndpoint*> m_testendpoint_items;
//QTableWidget *endpoint_table;
void Add_Data(string serial_num, TestEndpoint*e)
{
endpoint_table->setRowCount(endpoint_table->rowCount() + 1);
QLabel *lbl = new QLabel(serial_num.c_str());
endpoint_table->setCellWidget(endpoint_table->rowCount() - 1, 0, lbl);
m_endpoint_labels.push_back(lbl);
m_testendpoint_items.push_back(e->getEndpoint());
}
void MyQtApp::onRemoveFailedButton()
{
unsigned int count = 0;
// Look through all endpoints...
while(count < m_testendpoint_items.size()) {
// Is the endpoint offline?
if(!m_testendpoint_items[count]->getEndpoint().isOnline()) {
delete m_endpoint_labels[count];
m_testendpoint_items.erase(m_testendpoint_items.be gin() + count);
m_endpoint_labels.erase(m_endpoint_labels.begin() + count);
endpoint_table->removeRow(count);
} else count ++;
}
}
grantbj74
27th May 2010, 04:28
I found the problem.
I had a currentCellChanged() event that was being called.
Passing me currentRow = -1.
I was then doing the following, which I think crashed it.
QLabel* lbl = (QLabel *) endpoint_table->cellWidget(currentRow, ENDPOINT_DATA_COL);
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.