How to apply a mask to a qwebview in PyQt? - pyqt4

I'm trying with QWebView.mask() in PyQt4 or PySide or PySide2, for convert the transparent pixels of a transparent QWebView into a window mask, like a frameless window with custom shape, but not work, the window is translucent.
webview = QtWebKit.QWebView()
mask = webview.mask()
webview.setMask(mask)
Why this not work, what alternatives exist and how i can solve this?
note: I'm trying with QWidget too, and still not works.
widget = QtGui.QWidget()
mask = widget.mask()
widget.setMask(mask)
Something like this: Using an alpha transparent mask on a QWidget?
but for PyQt4, not for Qt, because im working on scripting...

Maybe this?
webview.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents)
This is applicable for BOTH, i hope this help you...

Related

Make canvas background transparent - python

So I am making a Frogger game, but have run into a problem. For the collision detection, I am using the following to check if one Tkinter canvas object is overlapping another:
canvas.find_overlapping(*canvas.bbox(imageObj))
However, I made the background a canvas object as well:
background = self.canvas.create_image(0, 0, image = self.imageData["Background"], anchor = "nw")
So the program is detecting a collision between the player and an object 24/7. Is there any way around this? I searched SO and tried putting the background in a label, but when I packed the canvas over it the background disappeared (probably because the canvas was covering it).
I can't find a way to make the canvas transparent without making the objects on it transparent as well. I also do not want to calculate the x and y boxes of each object, as that is just cumbersome and unreliable.
If someone could suggest another way, that would be awesome.
The find_overlapping method returns a list of items. Just cycle through the list and ignore the background item.

How do you create a perfect pygame fullscreen?

I am making a game, and I want it to be fullscreen. However, the pygame fullscreen is strange, creating a screen too large. So I referred to this: Pygame FULLSCREEN Display Flag Creates A Game Screen That Is Too Large For The Screen. However, when I followed these instructions
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
true_res = (ctypes.windll.user32.GetSystemMetrics(0), ctypes.windll.user32.GetSystemMetrics(1))
pygame.display.set_mode(true_res,pygame.FULLSCREEN)
from an answer (but instead using pywin32 instead of ctypes, like this: win32api.GetSystemMetric(0)).
I used this, and while it does create a fullscreen, it also creates a black border around my screen and enlarges everything a slight bit, including my cursor. How can I get rid of this black border and get all shapes to normal size? Or is there a better way to create a good fullscreen?
If it helps, I use Windows 10.
Thanks in advance!
I think the problem of enlarging everything arose with the use of ctypes module as because the ctypes module makes use of a function named as GetSystemMetrics() whose work is to get the size of the screen of your system.
And might be the import pygame is loading some dll that is not compatible with a dll that windll needs.
So I suggest either you update the ctype library or pygame library or update both libraries or you can enlarge screen size by providing custom width and height values according to the resolution supported by your system.
Hope this helps !!

PyQt Matplotlib colour control

Writing in Python 2.7 using pyQt 4.8.5:
How may I alter the background and graph-area (foreground?) of a Matplotlib widget? I would like to make the background of the graph widget 'light gray' (same as the background colour of the GUI), and I would like to make the graph-area (see below) black.
I'm new to GUI programming with pyQt and would like to achieve this:
my code:
self.ui.graph.axes.clear()
self.ui.graph.axes.hold(True)
self.ui.graph.axes.plot(self.Value,'r-')
self.ui.graph.axes.grid()
self.ui.graph.draw()
This should do it:
ax = self.ui.graph.axes
ax.set_axis_bgcolor('k')
self.ui.graph.set_facecolor('none')
This did only partly work for me. The two first lines worked fine but the last did not work. The error I got was:
AttributeError: 'MatplotlibWidget' object has no attribute 'set_facecolor'
The solution was to add figure to the code:
ax = self.ui.graph.axes
ax.set_axis_bgcolor('k')
self.ui.graph.figure.set_facecolor('none')
An interesting note is that I had been trying to solve this problem by using setPalette() but this didn't work until the facecolor was set to 'none' then suddenly all the changes I had made to the palette showed up.

Grabbing pixel attributes in Python

I am using Python3 on Windows 7. I want to grab all the attributes like color intensity, color etc. Of all the pixels of the screen area that I select with mouse. The selection can be of any shape but right now rectangular and square will do.
I want to do it in any area of the screen.
Can you guys please guide me how to do that in Python?
PS: If the method can work across all the platforms that would be much more appreciated.
Thanks,
Aashiq
You need to use some sort of cross-platform GUI toolkit, such as GTK or KDE, maybe Tk or wx will work as well, I don't know.
How you then do it depends on what toolkit you choose.

gtk3 transparent menu's

Is it possible in gtk3 to create a menu that is transparent? The underling window would use an image as it's background.
I can use a color for the window background but not a image.
I attempted to do what you said using an example from the gdk2 reference by adding a background image first and then porting it to gtk3. I'm no expert at gtk at all, but I did make it somehow compile:
http://pastebin.com/0XwUW5k3 (note that there has to be a "background.png" in the same folder)
The transparent dark rectangle holding the widgets is most likely the box; I tried settings its background color to full transparency as well, but it didn't work, and you'd probably have to do the composing/drawing of it yourself if you wanted it to be completely transparent, but that's not something I'd suggest because it seems too complex..
Also, you might want to create a background image with an already fitting resolution for the window, then you could skip the scaling part.
The scale function originally comes from this mailling-list thread

Resources