在 python 中创建一个没有框架的 QMainWindow 尽管它是可移动和可调整大小的

Create a QMainWindow in python without frame despite that it is movable and resizable

我想创建一个没有框架和标题栏的 QMainWindow,尽管它是可移动和可调整大小的我试过 self.setWindowFlags(Qt.FramelessWindowHint)但它不可移动或浮动。

我不明白你为什么想要你想要的东西......我假设,因为你没有 window 标题,你想通过单击拖动 window window 区域内的任意点,然后用鼠标拖动。请注意,如果 window 包含 child 也对鼠标按下和移动事件做出反应的小部件,这可能是个坏主意...

但这是基本的解决方案:

from PyQt4.QtCore import Qt
from PyQt4.QtGui import QApplication, QMainWindow

class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setWindowFlags(Qt.FramelessWindowHint)

    def mousePressEvent(self, event):
        # Store the positions of mouse and window and
        # change the window position relative to them.
        self.windowPos = self.pos()
        self.mousePos = event.globalPos()
        super(MainWindow, self).mousePressEvent(event)

    def mouseMoveEvent(self, event):
        self.move(self.windowPos + event.globalPos() - self.mousePos)
        super(MainWindow, self).mouseMoveEvent(event)

app = QApplication([])
wnd = MainWindow()
wnd.show()
app.exec_()