How to change the background colour of the QTableWidget?
-
Is it possible to change the QTableWidgets background colour at once?
Till now i was taking each QTableWidgetItem and changing its colour...
But thats taking time and sometimes crashing program,
So is there any other method to change the background colour of the QTableWidget? -
You can try change propertyes "base" in palette for parent widget yours QTableWidgets
-
But my problem not yet solved....
I tried to change its color as u told, it changes background color of all the items except the item which i changed before...Actually in my program i'm using a table widget and performing seraching operation on it....
Whenever a item found with given search key, i'm changing its background colour to red....i'm providing "NEXT" and "PREv" button, which changes background of one after the other found item...But problem is that---1.At the begin i'll highlight the first found item, by changing its background color to red, when i click on "next", only that next item must highlight but in my case previously item not changing back its color to default white.....
2. If i change the search key also, previously highlighted items(which is red background) not changing to default white color.....my code is as follows...
@
void MainWindow::FilterCurrentTab(void)
{
temp= dynamic_cast<QTableWidget*>(ui->tabWidget_2->currentWidget());
if (temp == NULL)
{
std::cout<<"Error. No Table widget found in Tab\n";
return;
}QTableWidgetItem *rowPtr; QPalette p=temp->palette(); p.setColor(QPalette::Background,Qt::white); <----when next search begins all item will be in white background temp->setPalette(p); QString SearchKey=ui->lineEdit_FilterKey->text(); LTempTable =temp->findItems(SearchKey,Qt::MatchExactly); Findcounter=0; LTempTable.at(0)->setBackground(Qt::red); temp->scrollToItem(rowPtr,QAbstractItemView::EnsureVisible); }
@
@ void MainWindow::on_pushButton_findPrev_clicked()
{
QPalette p=temp->palette();
p.setColor(QPalette::Background,Qt::white);
temp->setPalette(p);
Findcounter=Findcounter-1;
cout<<"THE FIND COUNT:"<<Findcounter<<endl;
LTempTable.at(Findcounter)->setBackground(Qt::red);
temp->scrollToItem(LTempTable.at(Findcounter),QAbstractItemView::EnsureVisible);
}
@@
void MainWindow::on_pushButton_FindNext_clicked()
{ QPalette p=temp->palette();
p.setColor(QPalette::Background,Qt::white);
temp->setPalette(p);
Findcounter++;
cout<<"THE FIND COUNT:"<<Findcounter<<endl;LTempTable.at(Findcounter)->setBackground(Qt::red); temp->scrollToItem(LTempTable.at(Findcounter),QAbstractItemView::EnsureVisible); }
@
please help me to solve this problem..
Thanks in advance...