Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15, 6.0, 6.1, 6.2, 6.3, 6.4, 6.5, 6.6
-
None
Description
In the following cases, a black background is drawn for date cells of QCalendarWidget having no custom text format set, and whenever the Base palette role is affected:
- gradients;
- colors with an alpha less than 255 set in style sheets;
- pixmaps set for the palette or set in style sheets and having an alpha channel or mask;
This can be simply reproduced using style sheets: while there is no reference about QCalendarWidget in the style sheet docs, the appearance of the internal QTableView can still be changed with QSS to some extent.
For example, the following simple QSS correctly draws an almost opaque white background for QTableView, and should do the same for date cells of QCalendarWidget that have no explicit QTextCharFormat set, but full black cells are drawn instead:
QTableView {
background: rgba(255, 255, 255, 254);
}
This is primarily caused by the fact that the data() function of the internal model of QCalendarWidget always returns the color() of the format's background brush for Qt::BackgroundRole, that will always result in a valid black QColor for the background, even if it's not the real background (and even if the original palette color is not valid).
If the background is a gradient, the palette color may not be valid and is normally black (implicit for style sheets, or explicitly set for the brush).
The same goes for brush that use pixmaps set for a palette (not QSS).
When using QSS, if the background is a non opaque color or is a pixmap with an alpha channel, QRenderRule::configurePalette() sets a NoBrush style for the background role whenever an embedding widget is detected. Again, a black color is returned.
I am not 100% sure, but I think that just changing to return fmt.background(); (the brush, not its color) for Qt::BackgroundRole should be sufficient, without causing much of a overhead.
Unfortunately, since drawBackground() is the only drawing function of QItemDelegate that is not virtual, overriding this behavior with a custom delegate is not as simple as expected.
In the meantime, if anyone is interested, I posted a PyQt based workaround on StackOverflow.