История изменений
Исправление Darth_Revan, (текущая версия) :
#!/usr/bin/env python3
import sys
from PySide2 import QtCore, QtGui, QtWidgets
class MainWindow(QtWidgets.QWidget):
def __init__(self, parent: QtWidgets.QWidget = None):
super(MainWindow, self).__init__(parent=parent)
self.setWindowTitle("Qt::WindowStates")
states = self.get_states()
print(states)
vbox = QtWidgets.QVBoxLayout(self)
vbox.setAlignment(QtCore.Qt.AlignHCenter)
self.label = QtWidgets.QLabel(states)
vbox.addWidget(self.label)
def changeEvent(self, event: QtCore.QEvent):
super(MainWindow, self).changeEvent(event)
if event.type() == QtCore.QEvent.WindowStateChange:
states = self.get_states()
print(states)
self.label.setText(states)
def get_states(self) -> str:
states = self.windowState()
str = []
if states == QtCore.Qt.WindowState.WindowNoState:
str.append("Qt::WindowNoState")
if states & QtCore.Qt.WindowState.WindowMinimized:
str.append("Qt::WindowMinimized")
if states & QtCore.Qt.WindowState.WindowMaximized:
str.append("Qt::WindowMaximized")
if states & QtCore.Qt.WindowState.WindowFullScreen:
str.append("Qt::WindowFullScreen")
if states & QtCore.Qt.WindowState.WindowActive:
str.append("Qt::WindowActive")
return ",".join(str)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Написал программу, которая делает ровно это.
В чём подвох?
Исходная версия Darth_Revan, :
#!/usr/bin/env python3
import sys
from PySide2 import QtCore, QtGui, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent: QtWidgets.QWidget = None):
super(MainWindow, self).__init__(parent=parent)
self.setWindowTitle("Qt::WindowStates")
states = self.state_as_string()
self.label = QtWidgets.QLabel(states)
self.setCentralWidget(self.label)
print(states)
def changeEvent(self, event: QtCore.QEvent):
super(MainWindow, self).changeEvent(event)
if event.type() == QtCore.QEvent.WindowStateChange:
states = self.state_as_string()
self.label.setText(states)
print(states)
def state_as_string(self) -> str:
states = self.windowState()
ret = []
if states == QtCore.Qt.WindowState.WindowNoState:
ret.append("Qt::WindowNoState")
if states & QtCore.Qt.WindowState.WindowMinimized:
ret.append("Qt::WindowMinimized")
if states & QtCore.Qt.WindowState.WindowMaximized:
ret.append("Qt::WindowMaximized")
if states & QtCore.Qt.WindowState.WindowFullScreen:
ret.append("Qt::WindowFullScreen")
if states & QtCore.Qt.WindowState.WindowActive:
ret.append("Qt::WindowActive")
return ",".join(ret)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
Написал программу, которая делает ровно это.
В чём подвох?