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?
Re: How to change the background colour of the QTableWidget?
Re: How to change the background colour of the QTableWidget?
Thank u Lykurg,
I tried like this .....
Code:
pal.
setColor(QPalette::Background,Qt
::white);
temp->viewport()->setPalette(pal);
But didnt get any effect...Please tell what am missing here?
Re: How to change the background colour of the QTableWidget?
Ehm, as I thought. You even don't need to use viewport. But you have to use the right color role!
Code:
w.setPalette(p);
w.show();
Re: How to change the background colour of the QTableWidget?
Lykung thanks a lot...
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...
Code:
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;
}
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);
}
Code:
void MainWindow::on_pushButton_findPrev_clicked()
{
p.
setColor(QPalette::Background,Qt
::white);
temp->setPalette(p);
Findcounter=Findcounter-1;
cout<<"THE FIND COUNT:"<<Findcounter<<endl;
LTempTable.at(Findcounter)->setBackground(Qt::red);
}
Code:
void MainWindow::on_pushButton_FindNext_clicked()
p.
setColor(QPalette::Background,Qt
::white);
temp->setPalette(p);
Findcounter++;
cout<<"THE FIND COUNT:"<<Findcounter<<endl;
LTempTable.at(Findcounter)->setBackground(Qt::red);
}
please help me to solve this problem..
Thanks in advance...
Re: How to change the background colour of the QTableWidget?
Well the background of the table widget surly does not overwrite the backgrounds of your items. Before highlighting the next/previous item simply change the old item back to white.
Re: How to change the background colour of the QTableWidget?
Or when you're starting to search change color for QPalette::Highlight on the table widget to red and 'select' item using setCurrentIndex().
When you're done with searching set the default palette back.
This way only currently selected items will have their background changed and as soon as you'll change to different item the previous one will go back to its old background.