PDA

View Full Version : QTableView change color of current Cell



raphaelf
3rd March 2006, 17:37
Hi everybody,

QT:4.1.1

I have a Table View with some cells.
Its possible to change the color of a cell by doble clicking it?And to change it again by leaving it? :rolleyes:

zlatko
3rd March 2006, 17:51
1) connect some slot to signal itemDoubleClicked ( QTableWidgetItem * item ) of your QTabLeWidget
2) use catched QTableWidgetItem * item for setting bg color( method setBackgroundColor)

jpn
3rd March 2006, 18:13
1) connect some slot to signal itemDoubleClicked ( QTableWidgetItem * item ) of your QTabLeWidget
2) use catched QTableWidgetItem * item for setting bg color( method setBackgroundColor)

For a QTableView you would connect to signals like:
void QAbstractItemView::doubleClicked ( const QModelIndex & index )
void QAbstractItemView::entered ( const QModelIndex & index )

I don't see any particular signal for leaving an item. But of course you can save row/col or a persistent index for the previously colourized cell and uncolourize during the entered signal of another item and possibly leave event of the whole table view..

wysota
3rd March 2006, 18:36
Its possible to change the color of a cell by doble clicking it?And to change it again by leaving it? :rolleyes:

Double clicking? Or single clicking? For a single click it should be enough to set the QPalette::Highlight role for the pallete in your view. Otherwise you'll have to subclass the table view (or use an event filter, but for model based widgets it could be too complex).

raphaelf
4th March 2006, 12:22
Hi everybody,
Thanks for replies..
It looks to be not easy..

I just would like to have a solution with colors like yellow or red, so that the user knows that he are in a dangerous process, like update a row..

I will try to implement all 3 posted example...but i think it will be not easy :cool: