[PyQt] Mouse Hover Event small issue
uahmed
gleam.uahmed at gmail.com
Tue Feb 21 23:43:10 GMT 2012
hi
Thanks for the reply thats exactly what i want , i already made a code of
more than 1000 lines(chunk of code is in program.py script) and when i try
to add your code for mouse over effect its not giving me required result .
i saved your script with the name of hover.py
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import pyqtSignal
import os,sys
class HoverButton(QtGui.QToolButton):
def enterEvent(self,event):
print("Enter")
self.setStyleSheet("background-color:#45b545;")
def leaveEvent(self,event):
self.setStyleSheet("background-color:yellow;")
print("Leave")
and then i call it from another program and include "hover.py"
"program.py"
import os,sys
from functools import partial
from PyQt4 import QtGui, QtCore
import hover
class main():
def Qbutton(self):
buttons["a1"] = QtGui.QToolButton(widget)
buttons["a1"].setIconSize(QtCore.QSize(200,200))
buttons["a1"] = hover.HoverButton()
app= QtGui.QApplication(sys.argv)
sk = main()
buttons = {}
widget = QtGui.QWidget()
sk.Qbutton()
widget.show()
sys.exit(app.exec_())
Can you please guide me how to add that script to program.py so it works
fine .It will really solve my problem .Thanks in advance
On Wed, Feb 22, 2012 at 2:08 AM, Hans-Peter Jansen <hpj at urpla.net> wrote:
> On Tuesday 21 February 2012, 03:27:41 uahmed wrote:
> > hi ,
> >
> > I want to do hover i saw an example and then write a script which
> > will be use as i made program i am facing one problem that hover only
> > occur if u putt mouse on the left corner of button i want that it
> > will happen for all the button that if i move cursor on button then
> > it should change. here is my code
> >
> > from PyQt4 import QtGui, QtCore
> > from PyQt4.QtCore import pyqtSignal
> > import os,sys
> >
> > class HoverButton(QtGui.QToolButton):
> > def enterEvent(self,event):
> > print("Enter")
> > button.setStyleSheet("background-color:#45b545;")
> >
> > def leaveEvent(self,event):
> > button.setStyleSheet("background-color:yellow;")
> > print("Leave")
> > app = QtGui.QApplication(sys.argv)
> > widget = QtGui.QWidget()
> > button = QtGui.QToolButton(widget)
> > button.setMouseTracking(True)
> > buttonss = HoverButton(button)
> > button.setIconSize(QtCore.QSize(200,200))
> > widget.show()
> > sys.exit(app.exec_())
>
> Hi uahmed,
>
> neither your description nor your code expresses your issue properly.
> Here's a simpler version, that might be helpful:
>
> from PyQt4 import QtGui, QtCore
> from PyQt4.QtCore import pyqtSignal
> import os,sys
>
> class HoverButton(QtGui.QToolButton):
> def enterEvent(self,event):
> print("Enter")
> button.setStyleSheet("background-color:#45b545;")
>
> def leaveEvent(self,event):
> button.setStyleSheet("background-color:yellow;")
> print("Leave")
>
> app = QtGui.QApplication(sys.argv)
> button = HoverButton()
> button.show()
> sys.exit(app.exec_())
>
>
> Pete
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120222/f38d5d80/attachment-0001.html>
More information about the PyQt
mailing list