[Android-development] Android Style (widget-based)
maitai at virtual-winds.org
maitai at virtual-winds.org
Mon Jul 7 11:17:42 CEST 2014
Hello all,
Following another conversation on this list, I have started modifying
qandroidstyle in order to fix or improve a few things.
Good news: I have implemented checkable groupboxes, and I also fixed
that annoying problem with spinboxes size. (QTBUG-37965 and QTBUG-38325)
I am now turning my attention on QTBUG-38717. The problem is with
QTableView headers size being wrong. What I discovered is that the
problem is not actually coming from androidStyle, but exists also with
QCommonStyle. It occurs only if a general styleSheet has been applied at
QApplication level, even if the styleSheet is not related to Headers.
For instance I have in my mainwindow constructor:
QString styleA="QToolBox::tab:unselected{color:black;"
"background-color:qlineargradient(x1: 0, y1: 0, x2: 1,
y2: 0,"
"stop: 1 #fffb90, stop: 0 #ffd800);}"
"QToolBox::tab:selected{color:white;"
"background-color:qlineargradient(x1: 0, y1: 0, x2: 1,
y2: 0,"
"stop: 1 #00a2ff, stop: 0 #2307ae);}";
qApp->setStyleSheet(styleA);
If I do that it changes somehow the font of tableViews, the font for
items is unchanged, but the font for headers becomes the default
application font, which is bigger. If I don't apply the stylesheet then
QTableView headers font is not changed, and all is fine. Note that this
strange change of tableView header's font occurs only on Android, on
Windows if I apply the styleSheet the header remain the same. That is
the first problem.
The second probem is that QCommonStyle does not catch the font for
headers. In QCommonStyle.cpp line 4782:
QSize txt = hdr->fontMetrics.size(0, hdr->text);
does not report the correct size, but the size as if the styleSheet was
not applied.
To fix it I reimplemented sizeFromContents in qandroidstyle for
CT_HeaderSection and replaced above line with
QSize txt;
if(qApp->styleSheet().isEmpty())
txt = hdr->fontMetrics.size(0, hdr->text);
else
txt = qApp->fontMetrics().size(0, hdr->text);
But of course this is a very bad hack...
So there are 2 questions:
Why applying a styleSheet at application level changes the font of
QTableView headers even if no header section is specified in the string?
How can I catch the actual font of header in a QStyle-derived class?
Thanks for any clue to improve on that one, it could also be that I
missed something...
Philippe LELONG
More information about the Android-development
mailing list