Results 1 to 7 of 7

Thread: How to change the background colour of the QTableWidget?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Oct 2011
    Posts
    160
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    31

    Default 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...

    Qt Code:
    1. void MainWindow::FilterCurrentTab(void)
    2. {
    3. temp= dynamic_cast<QTableWidget*>(ui->tabWidget_2->currentWidget());
    4. if (temp == NULL)
    5. {
    6. std::cout<<"Error. No Table widget found in Tab\n";
    7. return;
    8. }
    9.  
    10.  
    11. QPalette p=temp->palette();
    12. p.setColor(QPalette::Background,Qt::white); <----when next search begins all item will be in white background
    13.  
    14. temp->setPalette(p);
    15.  
    16.  
    17.  
    18. QString SearchKey=ui->lineEdit_FilterKey->text();
    19. LTempTable =temp->findItems(SearchKey,Qt::MatchExactly);
    20.  
    21. Findcounter=0;
    22. LTempTable.at(0)->setBackground(Qt::red);
    23. temp->scrollToItem(rowPtr,QAbstractItemView::EnsureVisible);
    24. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::on_pushButton_findPrev_clicked()
    2. {
    3. QPalette p=temp->palette();
    4. p.setColor(QPalette::Background,Qt::white);
    5. temp->setPalette(p);
    6. Findcounter=Findcounter-1;
    7. cout<<"THE FIND COUNT:"<<Findcounter<<endl;
    8. LTempTable.at(Findcounter)->setBackground(Qt::red);
    9. temp->scrollToItem(LTempTable.at(Findcounter),QAbstractItemView::EnsureVisible);
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::on_pushButton_FindNext_clicked()
    2. { QPalette p=temp->palette();
    3. p.setColor(QPalette::Background,Qt::white);
    4. temp->setPalette(p);
    5. Findcounter++;
    6. cout<<"THE FIND COUNT:"<<Findcounter<<endl;
    7.  
    8. LTempTable.at(Findcounter)->setBackground(Qt::red);
    9.  
    10. temp->scrollToItem(LTempTable.at(Findcounter),QAbstractItemView::EnsureVisible);
    11. }
    To copy to clipboard, switch view to plain text mode 
    please help me to solve this problem..
    Thanks in advance...
    Last edited by aurora; 11th January 2012 at 04:45.

Similar Threads

  1. Problem in QT treewidget background colour
    By keyurparekh in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2011, 23:46
  2. Replies: 2
    Last Post: 17th July 2010, 21:07
  3. Replies: 4
    Last Post: 17th July 2010, 04:47
  4. QTextDocument background colour
    By Ruud v A in forum Qt Programming
    Replies: 6
    Last Post: 18th May 2010, 14:30
  5. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.