将窗口拖到窗口最上方,或最左方,移开鼠标,窗口自动隐藏。
将鼠标移到窗口边界,窗口自动弹出,类音速启动效果
from PyQt4.QtGui imp
ort *
from PyQt4.QtCore imp
ort *
class Geometry(QDialog):
def __init__ (self):
QDialog.__init__(self)
self.frame=1
layout=QGridLayout(self)
btnAbout=QToolButton()
btnAbout.setText('About Qt')
btnAbout.setIcon(QIcon('hjz.png'))
btnAbout.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
layout.addWidget(btnAbout,0,0,Qt.AlignTop|Qt.AlignLeft)
self.connect(btnAbout,SIGNAL('clicked()'),self.slotAbout)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.resize(300,200)
self.show()
def slotAbout(self):
QMessageBox.aboutQt(self)
def enterEvent(self, evt):
self.activateWindow()
if(self.x() == self.frame-self.width()):
self.move(-self.frame,self.y())
elif(self.y() == self.frame-self.height()+self.y()-self.geometry().y()):
self.move(self.x(),-self.frame)
def leaveEvent(self,evt):
cx,cy=QCursor.pos().x(),QCursor.pos().y()
if(cx >= self.x() and cx <= self.x()+self.width()
and cy >= self.y() and cy <= self.geometry().y()):
return#title bar
elif(self.x() < 0 and QCursor.pos().x()>0):
self.move(self.frame-self.width(),self.y())
elif(self.y() < 0 and QCursor.pos().y()>0):
self.move(self.x(), self.frame-self.height()+self.y()-self.geometry().y())
if __name__=='__main__':
app=QApplication([])
win=Geometry()
app.setActiveWindow(win)
app.exec_()
将鼠标移到窗口边界,窗口自动弹出,类音速启动效果
from PyQt4.QtGui imp
from PyQt4.QtCore imp
class Geometry(QDialog):
def __init__ (self):
QDialog.__init__(self)
self.frame=1
layout=QGridLayout(self)
btnAbout=QToolButton()
btnAbout.setText('About Qt')
btnAbout.setIcon(QIcon('hjz.png'))
btnAbout.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
layout.addWidget(btnAbout,0,0,Qt.AlignTop|Qt.AlignLeft)
self.connect(btnAbout,SIGNAL('clicked()'),self.slotAbout)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.resize(300,200)
self.show()
def slotAbout(self):
QMessageBox.aboutQt(self)
def enterEvent(self, evt):
self.activateWindow()
if(self.x() == self.frame-self.width()):
self.move(-self.frame,self.y())
elif(self.y() == self.frame-self.height()+self.y()-self.geometry().y()):
self.move(self.x(),-self.frame)
def leaveEvent(self,evt):
cx,cy=QCursor.pos().x(),QCursor.pos().y()
if(cx >= self.x() and cx <= self.x()+self.width()
and cy >= self.y() and cy <= self.geometry().y()):
return#title bar
elif(self.x() < 0 and QCursor.pos().x()>0):
self.move(self.frame-self.width(),self.y())
elif(self.y() < 0 and QCursor.pos().y()>0):
self.move(self.x(), self.frame-self.height()+self.y()-self.geometry().y())
if __name__=='__main__':
app=QApplication([])
win=Geometry()
app.setActiveWindow(win)
app.exec_()