How to disable drag and drop and make window borderless
-
Hi,
So I am using a windows application that uses Qt, and there is a floating window which I want to modify.
Basically I want to make this window borderless, transparent, and also ignore all keyboard and mouse events and disable all drag and drop also.
The python interface is different than the standard qt so please ignore the differences.
Before I was using this:
mywidget.setWindowFlags(mywidget.windowFlags() | Qt.WindowTransparentForInput | Qt.FramelessWindowHint)and the window would immediately disappear. Now I sandwiched it between, mywidget.hide/show, and it works. Except it's not borderless, but at least the mouse events seem to be ignored.
But the issue is click and drag is NOT ignored. I have a feeling that's because the window/widget has drag and drop feature. I called setAcceptDrops to False but still the same.
So I am not sure how to make it work, or if it's because this window actually has many nested QtWidgets that I have to call the same function for all of them?
Thanks so much in advance.
Cheers,
Yunus -
Hi and welcome to devnet,
What version of Qt are you using ?
On what OS ?
You mention python, are you using PyQt5/PySide2 ?
Can you provide a minimal example ? -
Hi,
Thanks a lot :)
I think it's qt5, windows 10.
It's using PySide2.
I can show you some codes. I kind of bypassed the drag issue by overlaying window B over A, vs A over B because A has the overlay issue.
So now one of the next issues I ran into is, even though it seems to work, I am not able to bring the window back to front and remove the transparent for input flag.
Is there a way to list the flags of a widget? I tried widget.windowFlags but it just prints an object, I would have liked to see which flags are stored there so I can set them manually when the user turns this transparency off. Storing them in memory will be a bit harder.
As for code, this is the WIP code for now:
from PySide2 import QtCore, QtWidgets, QtGui from hutil.Qt import QtCore import time def setWindowToBG ( widget, state ): viewport.hide() widget.setAcceptDrops(not state) if state: widget.setWindowFlags(viewport.windowFlags() | QtCore.Qt.WindowTransparentForInput | QtCore.Qt.FramelessWindowHint) else: widget.setWindowFlags(QtCore.Qt.Window) widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, state) widget.setAttribute(QtCore.Qt.WA_TranslucentBackground, state) widget.setDisabled(state) if state: widget.setWindowOpacity(0.5) else: widget.setWindowOpacity(0.8) viewport.show() enabled = hou.node(".").evalParm("enable") posx = 29 posy = 119 sizex = 2635 sizey = 1767 name = "animatrix network editor" a = hou.ui.mainQtWindow() app = QtGui.QGuiApplication.instance() viewport = None desktop = hou.ui.curDesktop() panels = desktop.floatingPanels() viewport = None for p in panels: if name in p.name(): viewport = p allWidgets = app.allWidgets() for w in allWidgets: if name in w.windowTitle(): viewport = w break; print "before", viewport print "desktop", desktop if viewport == None: panel = desktop.createFloatingPanel(hou.paneTabType.NetworkEditor) panel.setName(name) panel.paneTabs()[0].setPin(False) print "view created" allWidgets = app.allWidgets() for w in allWidgets: if name in w.windowTitle(): viewport = w break; print "after creation", viewport if viewport: setWindowToBG ( viewport, enabled ) viewport.showFullScreen() viewport.resize(sizex, sizey) viewport.move(posx, posy) for v in viewport.children(): if v.isWidgetType(): viewport = v setWindowToBG ( viewport, enabled ) for v in viewport.children(): if v.isWidgetType(): viewport = v setWindowToBG ( viewport, enabled )
Thanks a lot again,
Yunus -
Ok so I am closer to the result but there is still some weird behaviour.
I now switch between states using this:
def setWindowToBG ( widget, state ): #widget.hide() if state: widget.setWindowFlags(viewport.windowFlags() | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowTransparentForInput) else: widget.setWindowFlags(viewport.windowFlags() | QtCore.Qt.FramelessWindowHint & ~QtCore.Qt.WindowTransparentForInput) #widget.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, state) #widget.setAttribute(QtCore.Qt.WA_TranslucentBackground, state) #widget.setDisabled(False) if state: widget.setWindowOpacity(0.05) else: widget.setWindowOpacity(0.5) #widget.show()
It works, but it flashes the entire screen. This is bad as I will perform this operation 100s of times while working. I tried a few different things and just now figured out that using FramelessWindowHint flag works. There is no more flash but now my top window is stuck in the BG, meaning it always have input transparency.
I have set the widget to show fullscreen and then resized it. I feel this might be causing the issue but when I didnt do this, I couldn't get the window frame and title removed.
Any ideas?
-
Glad you're on the right track !
Can you explain what the role of this window is in your application ?
-
Hi, it's basically a control panel type of window. Btw is there a way to create transparency in a widget using a color? I need both actual opacity but also mask out the window by color. But it's not my widget so I don't have access to its code or paint events.
So it has a background but it might not be the actual background qt supports.
-
You can paint your widget background setting the Alpha channel of the color.