Re: coloring of QTableView
[QUOTE=divanov;682125]
Selection colours are actually coming from Fremantle default themes, but if you don't like them for some reason, you can make custom themes for your application.[/QUOTE]
How can we have the rows/columns in Qtableiew/QListview/QTableWidget coloured in Fremantle ? Ive tried to implement a delegate to paint each row but it didnt seem to work fine. I would also like it to show a different color when selected.
Can this be elaborated please as to how it can achieved ?
this is my example, ive managed to color the text here , the Qt:Window color role didnt help in coloring the backround of the columns.
Thanks for the time.
[CODE]void TableViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QPalette pal = option.palette;
QStyleOptionViewItem viewOption(option);
if(index.column() == 1)
{
viewOption.palette.setColor(QPalette::Text, Qt::green);
}
else if (index.column() == 2)
{
viewOption.palette.setColor(QPalette::Text, Qt::red);
}
else if (index.column() == 3)
{
viewOption.palette.setColor(QPalette::Text, Qt::yellow);
}
else
{
viewOption.palette.setColor(QPalette::Text, Qt::white);
}
QStyledItemDelegate::paint(painter, viewOption, index);
}[/CODE]
Re: coloring of QTableView
Dear rkurvakat,
I am having a similar problem. I am using a QTableWidget and want some cells with different background colors. I tried the following:
[CODE]
...
item = QTableWidgetItem("")
item.setBackground( QtGui.QBrush(QtCore.Qt.red) )
# tw is of type QTableWidget
# tw.setStyle( QtGui.QWindowsStyle() )
tw.setItem(0, 0, item)
[/CODE]
Using the Hildon-Style the cell does _NOT_ have the specified background color. But if I use a different style (here: QWindowsStyle), the background color is applied. I assume that this issue has to do something with the Hildon-Style? Is there a way to override this faulty(?) behaviour?
Drawbacks of using a different style for the tablewidget:
[LIST=1][*]Inconsistent look&feel[*]Kinetic Scrolling does not work[/LIST]
Have a nice day,
Dominik
--
Working environment: N900, PySide + Qt 4.6.2
Re: coloring of QTableView
[QUOTE=bartenst;716709]
[CODE]item = QTableWidgetItem("")
item.setBackground( QtGui.QBrush(QtCore.Qt.red) )
# tw is of type QTableWidget
# tw.setStyle( QtGui.QWindowsStyle() )
tw.setItem(0, 0, item)
[/CODE][/QUOTE]
Alternatively you can do something like this:
[CODE]
model.setData(model.index(0, 0), QVariant(QBrush(Qt::red)), Qt::BackgroundRole);
[/CODE]
[QUOTE=bartenst;716709]
Using the Hildon-Style the cell does _NOT_ have the specified background color. But if I use a different style (here: QWindowsStyle), the background color is applied. I assume that this issue has to do something with the Hildon-Style? Is there a way to override this faulty(?) behaviour?[/QUOTE]
Maemo5 style is using Gtk pixmaps to draw background of the items, so one cannot really change the colour of background. The only way is to reimplement Maemo5 style and use the modified style in your application.
Re: coloring of QTableView
[QUOTE=divanov;717395]Alternatively you can do something like this:
[CODE]
model.setData(model.index(0, 0), QVariant(QBrush(Qt::red)), Qt::BackgroundRole);
[/CODE][/quote]
this doesnt work on Fremantle :-(
failed to color the text.
Re: coloring of QTableView
[QUOTE=rkurvakat;717717]this doesnt work on Fremantle :-(
failed to color the text.[/QUOTE]
And in my previous post it's explained why.
Re: coloring of QTableView
One possibilty seems to be in using a QItemDelegate which "bypasses" the Hildon style:
# delegate which overrides Hildon style
delegate = QtGui.QItemDelegate()
tablewidget.setItemDelegate(delegate)
...
# colors are accepted
item = QTableWidgetItem("")
item.setBackground( QtGui.QBrush(QtCore.Qt.red) )
Advantages:
- Kinetic scrolling still works because the tablewidget still uses Hildon style