2 Attachment(s)
Can't style QHeaderView::section:selected in QSS stylesheet
The title says it all: I seem unable to change the background color (or any other property) of a QHeaderView section using the QHeaderView::section:selected selector using Qt 4.7.0. Here's the relevant code:
Code:
{
background-color: red;
}
This is what I have now:
Attachment 7269
And this is what I would like to achieve (the selected section is highlighted):
Attachment 7270
According to the documentation, this ought to be possible:
Quote:
QHeaderView: Supports the box model. The sections of the header view are styled using the ::section sub control. The section Sub-control supports the :middle, :first, :last, :only-one, :next-selected, :previous-selected, :selected, and :checked pseudo states.
Am I doing it right?
(I couldn't find anything on that subject in the bug database, and I don't have Qt 4.8 handy to check if the behavior is different.)
Cheers,
Franz
Re: Can't style QHeaderView::section:selected in QSS stylesheet
Try the QHeaderView::section:checked selector... the section headers are like toggling push buttons. The :selected options seem more about formatting tab bars or lists (and nothing to do with selections).
Re: Can't style QHeaderView::section:selected in QSS stylesheet
Thanks for the suggestion. Unfortunately using the QHeaderView::section:checked selector has no effect either...
1 Attachment(s)
Re: Can't style QHeaderView::section:selected in QSS stylesheet
Works fine here:
Code:
#include <QtGui>
#include <QtSql>
#include "connection.h"
int main(int argc, char *argv[])
{
if (!createConnection())
return 1;
model.setTable("person");
model.select();
v.setStyleSheet( "QHeaderView::section:checked { background-color: green; }");
v.setModel(&model);
v.show();
return app.exec();
}
displays:
Attachment 7278
It also works if you apply the style sheet to just the horizontal or vertical header.
Re: Can't style QHeaderView::section:selected in QSS stylesheet
No luck here. Here's my test app, derived from yours but without the SQL stuff:
Code:
#include <QApplication>
#include <QStringList>
#include <QTreeWidget>
#include <QTreeWidgetItem>
int main(int argc, char *argv[])
{
v.setColumnCount(2);
v.setStyleSheet("QHeaderView::section:checked { background-color: green } QHeaderView::section:hover { background-color: red }");
v.setSortingEnabled(true);
v.show();
return app.exec();
}
Setting QHeaderView::section:hover works but setting QHeaderView::section:checked doesn't.
I also tried with QTableView as you did in your test, same problem.
Qt 4.7.0 on Windows Vista.
Thanks,
Franz
Re: Can't style QHeaderView::section:selected in QSS stylesheet
Linux and Qt 4.7.4: QTreeWidget does not work, QTableWidget does if the table has content.
Highlighting is part of the style... perhaps Windows Vista style does not honour it? I don't have a Vista box hand to try on.
Re: Can't style QHeaderView::section:selected in QSS stylesheet
I reported a bug: https://bugreports.qt.nokia.com/browse/QTBUG-23689.
Thanks all for your help.
Cheers,
Franz