2017-07-16 58 views

回答

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_() 
相關問題