Shading of icons in a Qt combobox possible? - qt

How can I set a "shading" for QCombobox icons?
I have a QComboxBox with text and icon entries. The icons are nation flags here. The combobox background color is white by default (on Windows). The problem is with the Japan flag, because just a red filled circle is displayed. In other words, I cannot distinguish the white flag color from the combobox background. My workaround is to overrule the combobox base color and set the RGB value to 3*250. Furthermore I don't think it's a good idea to draw a dark border in the original PNG image of the flag.
P.S.: What do you use as workaround for white on white? (I want to know if my workaround is the best solution...)

Related

Does Background Color Without Text Matter?

Regarding color contrast:
In this example, do I need to be careful of the blue background even though there is no copy directly on top of it? I.e. do I only need to be concerned with background color when there is copy on top of it, and I could hide the element with the background color from screen readers without causing an issue?
And in this one, do I need to be careful of the contrast between the light blue background and the button or am I only concerned with the contrast between the copy and the button? (I know the image is blurry. It's just an example.)
Both examples are fine as they are.
There are two things that are applicable here.
The first is contrast between text and the background for that text - you must have a contrast ratio of 4.5:1 for normal text and 3:1 for large text / bold text to be WCAG AA compliant. In the first example it is essentially black on white so it will pass easily.
The second is for controls. Buttons, inputs etc. should have a contrast ratio with their background of 3:1 minimum, no matter what state they are in (so if your above button turned white with black text on hover it probably wouldn't pass). In your second example your button is black on light blue so it certainly passes this also.
Also worth noting is that text within controls (your button) has the same 4.5:1 contrast requirement. Yet again white on black passes easily so you are fine.
Just check the contrast (almost certainly fine) on the red button with white text, reds and oranges can be deceiving in their contrast ratios (but as it is quite a dark red I am 99% sure you are fine just by looking at it).
For clarity your blue background in the first one could be 1% darker than the white box and it would be fine as it is not an interactive control that it surrounds.

Modify default widget text color with applied stylesheet of QTreeWidget items

I have a QTreeWidget (however this question relates to any kind of widget) in which I have items which, under certain circumstances change their foreground color to red using item.setForeground(0,QBrush(QColor("red"))).
Later they can change their foreground color back to black. But the problem is that if the widget has been set some stylesheet which has changed the foreground color to other than black, I am in trouble. My question is how to revert the color of an item to the default color used by the widget for text color given the applied stylesheets?
For example if I apply a dark stylesheet which makes widget background dark and default text color white, first I can see white items, then they change to red and then they become black. But I want them white again. But I do not know how to find that it is white (and not black) color they should change to.
I tried this:
1) if I use item.setForeground(QtGui.QBrush()) which I hoped would use empty and therefore default brush, I always get black text
2) if I query the text color treeWidget.palette().text().color() I always get the same color regardless of the stylesheet
This question doesn't really apply to "any kind of widget", because there is no guarantee that setting the foreground colour will always work. To quote from the docs for QPalette:
Warning: Some styles do not use the palette for all drawing, for
instance, if they make use of native theme engines. This is the case
for both the Windows XP, Windows Vista, and the Mac OS X styles.
However, if the question is restricted to model items (such as QTreeWidgetItem), you can clear the current settings like this:
item.setData(column, QtCore.Qt.ForegroundRole, None)
On platforms that do allow changes via the palette, you could get the default palette like this:
palette = QtGui.qApp.style().standardPalette()
which should then allow you to restore the original values.

Stop QLabel text blending with background colour

In short
I'm trying to get the text in my QLabel to paint as if it were over a black background, ignoring the real background colour.
In depth
I have a QLabel in a green coloured widget, the text is anti-aliased and white, the anti-aliasing softens the edges of the text by blending with the green background colour.
Hardware detects the exact green colour and uses it like a green screen to display some techno-wizardry without also drawing over my software overlay, it makes the background look black.
The anti-aliased text has a fuzzy green halo where it has slightly changed the green colour and hardware doesn't overwrite it.
I want the text to be draw as if it were over a black background
What I've tried
I have tried using a black opaque QGraphicsDropShadowEffect to be drawn under the text, thus giving the text a black background to draw on, this led to a bigger green halo around the text.
I have tried setting various QBrushes in the label's QPalette for the Qt::WindowText and Qt::Base ColorRoles.
I have re-implemented the paintEvent and I am trying to use style()->drawItemText(... ) to avoid re-implementing all the helpful alignment code.
I have tried intercepting the QStyleOpt parameter and setting its QPalette's background colour to black, however that didn't change anything, I still get fuzzy, greenish text.
I have tried various QBrush and QPen colours in the QPainter.
I'm really close using a QPainterPath in an overidden paintEvent function (in a class extending QLabel) where I paint a black path of the text behind the text, then I call QLabel::paintEvent and let it draw the text over the top. The issue here is that in some cases the path is clipped to smaller than the widgets rect() on the left hand side, scope for another question I think!
What I could try but haven't worked out yet
I could give the text a black outline as per this question however I'm using a QWidget not a QGraphicsView text item, and then the black outline would still probably blend with the green background.
Compromises I've already thought of and want to avoid
I could set the QLabel background to black, leaving large rectangles of black over the resulting overlay, unfortunately the labels are often much larger than the text being displayed.
I could stop the font being anti-aliased, this looks quite ugly and it stops all fonts being uniform across the product.

Disabled QGroupBox title shadow (aka etching)

Look thoroughly at the disabled QGroupBox title (see attached image).
You'll notice a tiny white 1-pixel shadow under the title's letters.
It's barely noticeable on default style sheet, but it can be much more annoying if you set dark background and text color.
What can I do to disable this shadow, or at least change its color?
What style are you using? It looks like the 'basic' Windows style. If you want to get rid of the text shadow, you can implement your own style and change the way the text is drawn for disabled group boxes. Read more about about QStyle and how to create a custom style here. The link is for Qt 5.1, but the principle is the same for Qt 4 as well.
An easier way would be to simply change the palette for the QGroupBox object. Change the color identified by color group QPalette::Disabled and color role QPalette::Light to any color with the alpha channel set to 0, e.g. QColor(0, 0, 0, 0). This will effectively disable the text shadow. However, it will also disable the shadow of the lines so it might not be what you want.
I've found a solution:
Unfortunately, you can't remove disabled text shadow (aka etching), but you can change its color using dirty workaround:
It looks like shadow effect always takes its color from the ColorGroup "Disabled" and the ColorRole "Light" of the current palette. So, you just set this color to the background color of your widget:
QPalette p = myWidget->palette();
p.setColor(QPalette::Disabled, QPalette::Light, QColor(0,0,0)); <- place your widget bg color here
myWidget->setPalette(p);
I've found this solution here

How to give back groundcolor to widget?

i my qt application i have a window and i set the background color of the window as white using "Change stylesheet'when i placed a button its background color is also the white.....i want the green window with button with a background color of grey...how to achieve this?
You need to set the autoFillBackground property to true on the widget.
Otherwise the background color, you have selected, will have no effect.
If this is not the case, please write a better description of the problem.

Resources