Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyside Remove window flags

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?

like image 410
jonathan topf Avatar asked Jan 03 '14 01:01

jonathan topf


2 Answers

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()))
like image 139
ekhumoro Avatar answered Nov 09 '22 07:11

ekhumoro


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
like image 3
absifreei Avatar answered Nov 09 '22 08:11

absifreei