我想创建一个没有框架和标题栏的QMainWindow,尽管它是可移动的和可调整大小的我试过self.setWindowFlags(Qt.FramelessWindowHint)
但是它不可移动或可浮动。
答案 0 :(得分:0)
我不明白为什么你想要你想要的东西...我认为,因为你没有窗口标题,你想通过点击窗口区域内的任何点然后拖动来拖动窗口用鼠标。请注意,如果窗口包含子窗口小部件,这也会对鼠标按下并移动事件做出反应,这可能是个坏主意...
但这是基本的解决方案:
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_()