Im designing a Pyside Qt application and I want to toggle the QtCore.Qt.WindowStaysOnTopHint
window flag in my main window. Setting this hint using this code works fine:
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.show()
but I can't work out how to remove a window flag using Pyside.
Does anybody know how to do this?
Window flags would normally be OR'd together with the existing flags:
print(int(self.windowFlags()))
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
print(int(self.windowFlags()))
Then to remove the flag, AND it out using the flag's negation:
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
print(int(self.windowFlags()))
You can toggle the window's showing at the top or bottom like this:
def toggleFunc(self):
if self.someCheckedButton.isChecked(): #show up at the top
self.setWindowFlags(self.theMainWindow.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
else: #show up at the bottom
self.setWindowFlags(self.theMainWindow.windowFlags() & ~QtCore.Qt.WindowStaysOnTopHint)
self.show() #it's important to show up the window again after changing the window flags
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With