How to simply change the background colour of a cell inside a TableView
-
I agree with you TblModel->setData returns false.
But my main issue still that I am not able to combine all your information/hints/code parts to one working unit.
1:
I have created a header file with the content of "https://pastebin.com/gmNCuUFk"
Do not know what to do with it.2:
and I also tried to run your code posted on
VRonin 15. Dez. 2017, 10:313:
And this point
VRonin: 1.Add this proxy between your model and your view
Do not know how towrote on 8 Feb 2018, 10:02 last edited by@G4bandit said in How to simply change the background colour of a cell inside a TableView:
Do not know how to
It's the same as
QSortFilterProxyModel* proxyModel = new QSortFilterProxyModel(this); proxyModel->setSourceModel(TblModel); ui->TV_DBOut->setModel(proxyModel);
but instead of
QSortFilterProxyModel
useExtraRolesProxyModel
-
wrote on 8 Feb 2018, 10:09 last edited by
-
wrote on 8 Feb 2018, 12:10 last edited by G4bandit 2 Aug 2018, 12:10
If someone ask how to change the color of headers,- here is a helpful link:
tview->model()->setHeaderData(0,Qt::Horizontal,QBrush(QColor("red")),Qt::BackgroundRole); tview->show(); QApplication::setStyle(QStyleFactory::create("Fusion"));
The last line was on my PC (Win) necessary to get the effect.
-
wrote on 17 Aug 2018, 14:00 last edited by
@G4banditi need to do somo simililar can help me please , i cant understand
-
wrote on 17 Aug 2018, 14:38 last edited by
I now implemented a generic proxy for this, I called it Role Mask Proxy Model. I have an example that changes the background, it uses
QStringListModel
but it's exactly the same with other base models -
I now implemented a generic proxy for this, I called it Role Mask Proxy Model. I have an example that changes the background, it uses
QStringListModel
but it's exactly the same with other base modelswrote on 17 Aug 2018, 15:44 last edited by@VRonin so mucth thanks , wonderfull library, i can do
-
wrote on 17 Aug 2018, 16:02 last edited by
if i use a QSqlRelationalTableModel, Role Mask Proxy Model works????
-
if i use a QSqlRelationalTableModel, Role Mask Proxy Model works????
wrote on 17 Aug 2018, 16:36 last edited byYes, works on any model
-
wrote on 21 Aug 2018, 13:30 last edited by paul_espinosa
@VRonin thanks for your help, now i have a problem, i can not save the data of my QSqlTableModel , i used the example exem_rolemaskeditablesql.cpp i can edit the data but i can not save,
-
wrote on 21 Aug 2018, 13:36 last edited by
If you call
addMaskedRole
passing eitherQt::DisplayRole
orQt::EditRole
any change will stay in the proxy and not be passed to the source model.You should only mask the roles that you need, in this case
Qt::BackgroundRole
.If it's still not clear, please post us the code using RoleMaskProxyModel and we'll be more specific on the changes to make