View Full Version : change color/focus in qtablewidget
mmm286
4th March 2010, 16:12
I try to explain my doubt.
I have six tables (6 qtablewidget) and a button.
When I push the button, it executes some code and I would like that the focus of the six tables goes to a determinate row,col and the color of the row change.
Is that possible? Could you give some help?
Many thanks and sorry for my english!
aamer4yu
4th March 2010, 16:50
You will need to subclass the QTAbleWdget and add some variable for the row/col you want to change the color of.
Then use delegate to change the color of the row/col
When you click the button, perform your actions and then update the variable
Lykurg
4th March 2010, 20:49
You also can try QTableWidget::item() and QTableWidgetItem::setBackground().
mmm286
5th March 2010, 09:50
Thanks
I try:
QTableWidgetItem *hitem = new QTableWidgetItem;
hitem->setBackground(QBrush(QColor(255, 0, 0, 7)));
tabla->setVerticalHeaderItem(3, hitem); // item is placed on the header of row r
tabla->setHorizontalHeaderItem(1, hitem);
tabla->setItem(1,1,hitem);
If I do this, the verticalheader and the horizontalHeader changes the color but the cell (1,1) doesnt change.
Any help?
EDIT
--------------------
Well, I do it.
tabla->item(estara-1,0)->setBackground(QBrush(hola.fromHsv(0,75,255,255)))
The other question.
The tablewidget is short, so when my program finds the appropiate cell I would like to the table moves automatically to this cell. This is possible?
Many thanks and sorry for my english!
aamer4yu
5th March 2010, 12:24
QTableWidgetItem::setSelected :rolleyes:
toutarrive
7th March 2010, 18:21
Or even use a style sheet.
tableview.setStyleSheet("background-color: wathevercolor")
toutarrive
14th March 2010, 14:11
To set the background color of selected text or item:
mytableWidget.setStyleSheet(selection-background-color : acolor")
stoneYa
5th June 2013, 03:58
To set the background color of selected text or item:
mytableWidget.setStyleSheet(selection-background-color : acolor")
if i want to change the row's background which i selected with a image? how should i do?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.