[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Mouse Hover Event small issue
From:       uahmed <gleam.uahmed () gmail ! com>
Date:       2012-02-21 23:43:10
Message-ID: CAEUvQQxsBOnRZCfb-ew3KxSXcRO9f5vLQuF+ZtYxfoXWF_=ZkA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@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@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

[Attachment #5 (text/html)]

<div dir="ltr">hi<br><br>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 .<br> \
<br>i saved your script with the name of hover.py<br><br>from PyQt4 import QtGui, \
QtCore<br>from PyQt4.QtCore import pyqtSignal<br>import os,sys<br><br>class \
HoverButton(QtGui.QToolButton):<br>   def enterEvent(self,event):<br>  \
print(&quot;Enter&quot;)<br>       \
self.setStyleSheet(&quot;background-color:#45b545;&quot;)<br><br>   def \
leaveEvent(self,event):<br>       \
self.setStyleSheet(&quot;background-color:yellow;&quot;)<br>       \
print(&quot;Leave&quot;)<br> <br>and then i call it from another program and include \
&quot;hover.py&quot; <br><br>&quot;program.py&quot;<br><br>import os,sys<br>from \
functools import partial<br>from PyQt4 import QtGui, QtCore<br>import hover<br>class \
main():<br>  def Qbutton(self):<br>                buttons[&quot;a1&quot;] = \
QtGui.QToolButton(widget)<br>                \
buttons[&quot;a1&quot;].setIconSize(QtCore.QSize(200,200))<br>                \
buttons[&quot;a1&quot;] = hover.HoverButton()<br> app= \
QtGui.QApplication(sys.argv)<br>sk = main()<br>buttons = {}<br>widget = \
QtGui.QWidget()<br>sk.Qbutton()<br>widget.show()<br>sys.exit(app.exec_())<br><br>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 <br> <br><br><br><div class="gmail_quote">

On Wed, Feb 22, 2012 at 2:08 AM, Hans-Peter Jansen <span dir="ltr">&lt;<a \
href="mailto:hpj@urpla.net" target="_blank">hpj@urpla.net</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">


<div><div>On Tuesday 21 February 2012, 03:27:41 uahmed wrote:<br>
&gt; hi ,<br>
&gt;<br>
&gt; I want to do hover i saw an example and then write a script which<br>
&gt; will be use as i made program i am facing one problem that hover only<br>
&gt; occur if u putt mouse on the left corner of button i want that it<br>
&gt; will happen for all the button that if i move cursor on button then<br>
&gt; it should change. here is my code<br>
&gt;<br>
&gt; from PyQt4 import QtGui, QtCore<br>
&gt; from PyQt4.QtCore import pyqtSignal<br>
&gt; import os,sys<br>
&gt;<br>
&gt; class HoverButton(QtGui.QToolButton):<br>
&gt;     def enterEvent(self,event):<br>
&gt;         print(&quot;Enter&quot;)<br>
&gt;         button.setStyleSheet(&quot;background-color:#45b545;&quot;)<br>
&gt;<br>
&gt;     def leaveEvent(self,event):<br>
&gt;         button.setStyleSheet(&quot;background-color:yellow;&quot;)<br>
&gt;         print(&quot;Leave&quot;)<br>
&gt; app = QtGui.QApplication(sys.argv)<br>
&gt; widget = QtGui.QWidget()<br>
&gt; button = QtGui.QToolButton(widget)<br>
&gt; button.setMouseTracking(True)<br>
&gt; buttonss =  HoverButton(button)<br>
&gt; button.setIconSize(QtCore.QSize(200,200))<br>
&gt; widget.show()<br>
&gt; sys.exit(app.exec_())<br>
<br>
</div></div>Hi uahmed,<br>
<br>
neither your description nor your code expresses your issue properly.<br>
Here&#39;s a simpler version, that might be helpful:<br>
<div><br>
from PyQt4 import QtGui, QtCore<br>
from PyQt4.QtCore import pyqtSignal<br>
import os,sys<br>
<br>
class HoverButton(QtGui.QToolButton):<br>
    def enterEvent(self,event):<br>
        print(&quot;Enter&quot;)<br>
        button.setStyleSheet(&quot;background-color:#45b545;&quot;)<br>
<br>
    def leaveEvent(self,event):<br>
        button.setStyleSheet(&quot;background-color:yellow;&quot;)<br>
        print(&quot;Leave&quot;)<br>
<br>
app = QtGui.QApplication(sys.argv)<br>
</div>button = HoverButton()<br>
button.show()<br>
sys.exit(app.exec_())<br>
<br>
<br>
Pete<br>
_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> \
</blockquote></div><br></div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic