码迷,mamicode.com
首页 > 其他好文 > 详细

AMovableLabel例子

时间:2014-07-22 22:35:35      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:os   re   c   ar   python   window   

#! /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

AMovableLabel例子

标签:os   re   c   ar   python   window   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/3860932.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!