#! /us/bin/env python
from PyQt4 import QtCore, QtGui
class AMovableLabel(QtGui.QLabel):
def __init__(self, parent=None):
super(AMovableLabel, self).__init__(parent)
self.parent = parent
self.mouseX = False
self.mouseY = False
def mouseDoubleClickEvent(self, ev):
self.parent.maximize()
def mousePressEvent(self, ev):
self.mouseX = ev.globalX()
self.origX = self.parent.x()
self.mouseY = ev.globalY()
self.origY = self.parent.y()
def mouseMoveEvent(self, ev):
if self.mouseX and self.mouseY and not self.parent.isMaximized():
self.parent.move(self.origX + ev.globalX() - self.mouseX,
self.origY + ev.globalY() - self.mouseY)
def mouseReleaseEvent(self, ev):
self.mouseX = False
self.mouseY = False
class AMovableWindow(QtGui.QMainWindow):
def __init__(self, parent=None, hints = QtCore.Qt.Widget):
super(AMovableWindow, self).__init__(parent, hints)
self.parent = parent
self.mouseX = False
self.mouseY = False
def minimize(self):
self.setWindowState(QtCore.Qt.WindowMinimized)
def maximize(self):
if self.isMaximized():
self.setWindowState(QtCore.Qt.WindowNoState)
else:
self.setWindowState(QtCore.Qt.WindowMaximized)
def mousePressEvent(self, ev):
self.mouseX = ev.globalX()
self.origX = self.x()
self.mouseY = ev.globalY()
self.origY = self.y()
def mouseMoveEvent(self, ev):
if self.mouseX and self.mouseY and not self.isMaximized():
self.move(self.origX + ev.globalX() - self.mouseX,
self.origY + ev.globalY() - self.mouseY)
def mouseReleaseEvent(self, ev):
self.mouseX = False
self.mouseY = False
AMovableLabel例子,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/mhxy13867806343/p/3860932.html