I've looked into the documentation for Qt Style Sheets and found out I could change the background colour of my widgets and even set transparency.
Here is code snippet that should---according to me---work:
application = QtGui.QApplication(sys.argv)
application.setStyleSheet(QtCore.QString('MainWindow {background-color: rgba(20, 0, 0, 75%)}'))
And indeed it works to the extent the background colour of the window is changed to the corresponding RGB values. However, as far as I can tell, the alpha value has no effect on my application.
EDIT: I realise the alpha channel is working now, only the application's background or canvas (I'm not sure how I should call it) is black. I need to make that transparent, not the main widget. How can I achieve this?
NB: I'm running on Ubuntu 11.04 with Gnome (but should that matter?).
I've found one answer elsewhere on SO but tags hadn't led met to it in the first place. So I'm going to answer my own question here:
The Qt Style Sheet will provide transparency for widgets only, but those are painted on black canvas. In order to make this canvas transparent, an attribute of the main widget should be changed like so:
self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
This however provides a radical solution only: the entire window is transparent, but there is no way to set partial transparency like this. So I'm not entirely satisfied with this answer.
I also have problems with this code widget.setStyleSheet("background-color: rgba(20, 0, 0, 75%);"), but when I change to something like this widget.setStyleSheet("background-color: rgba(255, 0, 0, 75%);") it worked.
For widgets with parents (as in you case) you can use setMask and provide a mask with an alpha channel. Its particulary usefull for widgets with irregular shapes.
Related
I am developing a widget which utilizes exact color values, anything different and the results are incorrect. After spending time tracking down why Chrome is incorrect, I found that Chrome is probably applying color management to my colors.
If I load up my canvas in Edge (the Chromium based version), and load up the canvas in Chrome, I then do a snippet and load it up in Gimp. For Edge my 100% green appears to be RGB(0, 255, 0), for Chrome my 100% green appears to be (0, 255, 60).
Unfortunately, while this kind of color management is a good thing, it is entirely the wrong thing for my application. Is there a generic way to disable color management or a way to probe what the end correction will be so I can counteract it? Kind of messed up that you can't tell a browser to just display a color in the exact way you want.
As an example, Chrome inspector says my CSS is RGB(0, 255, 0), yet, it is rendering a different color in browser. If this is not color management, then why? If it is color management, I would like to override it, as it is 'correcting' the color into incorrectness.
Edit:
Further research shows this is maybe from a recent update:
https://www.faqforge.com/windows/fixed-google-chrome-wrong-color-after-update/
Curious if this is future intended behavior or just a temporary bug.
Edit 2: Forcing Chrome to sRGB fixed the issue on my browser. Sounds like Chrome maybe is defaulting to a non-standard color profile with a recent release.
I want to make a green button. I did this:
self.detectButton.setStyleSheet("background: #00ff00")
Here it was before the styling:
And after:
As you can see, the color changed, but the rounded corners were lost.
What's the proper way to style the color so the corners are not lost?
Secondarily, is there any way to get a theme-generic "ok" button color? This won't look the same on other platforms.
Do not use stylesheets if you want completely consistent results on all platforms. The reasons for this are explained in this answer.
If you only need to set the background colour, use the widget's palette:
palette = self.detectButton.palette()
palette.setColor(QtGui.QPalette.Button, QtGui.QColor('#00ff00'))
self.detectButton.setPalette(palette)
It seems unlikely that there's a systematic way to generate colours that work equally well on all platforms. Probably the best you can do is try to tweak one of the system colours that are accessible via the palette color roles.
EDIT:
It seems I was wrong to assume that the palette method is a reliable cross-platform solution. The Qt docs for QPalette has the following:
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 OS X styles.
So it seems there isn't even a completely consistent, cross-platform way to do something as simple as changing the background colour.
I'm not familiar with Python, but I am assuming it removed all the other styles when you manually set that one.
I wonder if something like the following would work?
self.detectButton.setStyleSheet("background: #00ff00; border:1px solid #ccc; border-radius: 3px;")
It may have different syntax for multiple styles though.
I am looking to change the background color of a button in my GUI application to default.After searching online, i saw that
button1.SetBackgroundColour(wx.NullColor) does not seem to work. I am using python 2.7.
Is there any other way I could set it to default color with out using system colors
A little late, but maybe someone else has the same problem.
Did you try
button1.SetBackgroundColour(wx.NullColour)
So, write "Colour" instead of "Color", the non-American writing. This worked for me.
If wx.NullColour doesn't work, a solution is to decode the RGB code for the colour you seek and apply it to your background.
E.g. the background color on my wx GUI is the light grey from Windows, its RGB code is R=240, G=240, B=240 (you can measure this using Paint for instance).
Then this should work:
button1.SetBackgroundColour(wx.Colour(240, 240, 240))
Of course if you want your GUI to be portable on other systems this isn't the best option since this light grey is only the default colour in Windows.
With Python 2.7.17 and wxPython 3.0.2.0 the following seems to work:
button1.SetBackgroundColour('')
I think that the solutions do not work because wxPython works with a style system. I was able to change foreground & background colours with the SetStyle method.
I was styling a wx.TextCtrl where I needed to highlight the text I search for.
First, I stored the existing colours to variables.
bc = self.te.GetBackgroundColour()
fc = self.te.GetForegroundColour()
self.bcol = wx.Colour(bc[0], bc[1], bc[2], bc[3])
self.fcol = wx.Colour(fc[0], fc[1], fc[2], fc[3])
Change the colours with SetStyle
self.te.SetStyle(x, y, wx.TextAttr(wx.BLACK, wx.LIGHT_GREY))
And reset it back to the original colours:
self.te.SetStyle(0, -1, wx.TextAttr(self.fcol, self.bcol))
I have some CSS for displaying a reflection on an element which uses -webkit-gradient to fade out:
.foo { -webkit-box-reflect: below 0 -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), to(rgba(255, 255, 255, 0.5)), color-stop(0.7, transparent)); }
On browsers which support -webkit-box-reflect such as chrome, this displays a reflection of the element which gradually fades out as expected.
On browsers which don't support it at all, no reflection is show.
However, on Android's browser, a reflection is shown, but doesn't fade out.
Is there any way of getting Android to either:
fade out the reflection, or
not show the reflection at all.
I know I could use javascript to detect the browser and change the style accordingly, but I'd much prefer a CSS-only solution.
Without an example file or link, it is a little difficult to see what you need.
I also played with some reflection stuff a few months ago and didn't find anything that could do what you describe. I have some steps to get you what you want, outside of code. I recommend the item you wish to reflect be a PNG on a transparent background, to start.
The steps:
1.Take the image into your favorite image manipulation program (ex. Photoshop)
Double or extend the image canvas the necessary amount to include the reflection in the appropriate direction
Duplicate the layer (Photoshop-Layer/Duplicate Layer)
Reflect the image. (Photoshop-Layer/Image Rotation/Flip Canvas (your direction))
Move the duplicated layer such that it appears as a mirror using the Move tool
Select the Marquis tool, and set the edge blur to about 50% of your original image width.
Drag your cursor over the "reflected" layer, don't worry if it says the selection lines won't be visible, unless it says nothing was selected. If it says nothing was selected, reduce your edge blur to about 25% and try again.
Once you have a selection, be it visible or not, delete the selected area. This should give you a "reflected" look.
If desired, add a background on a layer below everything else.
Save your image as a jpg if you don't have a transparent background or a png if you do. Use it in place of the image you were reflecting and fading with code. This will be mostly browser compatible.
CSS isn't designed to handle stuff like that. In other words: no, it's not possible.
I'm having similar problems trying to do things with background gradients in the Android browser, and it appears completely unsupported
Unfortunately the above answer is right, there isn't a way to split your declaration up in a nice progressively enhanced way. You could use JavaScript/modernizr as you mentioned, and at least set a support class(es) so you don't actually have to flip the style within code.
You could try reproducing this effect with a HTML canvas element, using drawImage with your image and transforming it. Although canvas can be slow in mobile webkit.
Good luck
do gradients work at all in the android browser?
if they do, make sure you're using the correct version. There's an old webkit format you may need to use.
If not, just use modernizr to hide it on places that don't support gradients.
I have a canvas which I want to accept drags on.
I have added a dragOver and dragEnter event listeners to the canvas, but they only work if I drag over something inside the canvas (another child element).
I realised that if I set the canvas' background colour to black it works. So I have set it's background transparency to 0, which works... buy is there a better way to work around this apparent need for the canvas to have something inside it to accept dragEvents.
Thanks
Rob
According to one of the Flex developers, "In Flash there is a difference between a transparent pixel and an area in a Sprite that hasn't been drawn on at all." (http://www.mail-archive.com/flexcoders#yahoogroups.com/msg127690.html)
I'm guessing this is the reason why you need to have the transparent background. For what it's worth, this is always the way I've seen this problem solved. There is also this question which talks about this problem.
Hope this helps!