首页 > 代码库 > PyQt4中无边框窗口的移动(拖动)

PyQt4中无边框窗口的移动(拖动)

import sys

from PyQt4.QtGui import *

from PyQt4.Qt import *

from PyQt4.QtCore import *

class AboutUsDialog(QDialog):

    def __init__(self):

        super(AboutUsDialog,self).__init__()

        self.setWindowFlags(Qt.FramelessWindowHint|Qt.Dialog)

    def mousePressEvent(self, e):

        if e.button()==Qt.LeftButton:

            self.move1=e.globalPos()-self.frameGeometry().topLeft()

            QApplication.postEvent(self,QEvent(174))

            e.accept()

    def mouseMoveEvent(self, e):

        if e.buttons()==Qt.LeftButton:

            self.move(e.globalPos()-self.move1)

            e.accept()

 

app = QApplication(sys.argv)

aboutus = AboutUsDialog()

aboutus.show()

sys.exit(app.exec_())

如图:

PyQt4中无边框窗口的移动(拖动)