Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:32:30+00:00 2026-06-11T00:32:30+00:00

I made the gui in Qt Designer and then converted it into python using

  • 0

I made the gui in Qt Designer and then converted it into python using pyuic4. Now i want to capture the mouseover event on the buttons.

class window_b(QtGui.QDialog):
    def __init__(self,parent=None):
        super(window_b, self).__init__(parent)
        window_a.setEnabled(False)
        self.ui = Ui_Form_window_b()
        self.ui.setupUi(self)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
    def mouseMoveEvent (self,event):
        source= self.sender()
        #print source.name()
        # The action I want to do when the mouse is over the button:
        source.setStyleSheet("background-color:#66c0ff;border-radiu‌​s: 5px;")

I put the mouseMoveEvent method on the widget and I want to detect which button on the Dialog sent the mouseOver event. I tried source.name() but it throws me this error

print source.name()
AttributeError: 'NoneType' object has no attribute 'name'

Any suggestion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:32:31+00:00Added an answer on June 11, 2026 at 12:32 am

    sender() is only useful for signals but the mouse hovering is an event not a signal (actually 2 events: QEvent.Enter and QEvent.Leave).

    And to be able to handle events outside the buttons that received them, you need to install your window_b instance as an event filter for each button.

    class window_b(QtGui.QDialog):
        def __init__(self,parent=None):
            super(window_b, self).__init__(parent)
            window_a.setEnabled(False)
            self.ui = Ui_Form_window_b()
            self.ui.setupUi(self)
            self.setFocusPolicy(QtCore.Qt.StrongFocus)
    
            # Get all the buttons (you probably don't want all of them)
            buttons = self.findChildren(QtGui.QAbstractButton)
            for button in buttons:
                button.installEventFilter(self)
    
        def eventFilter(self, obj, event):
            if event.type() == QtCore.QEvent.Enter:
                print("mouse entered %s" % obj.objectName())
            elif event.type() == QtCore.QEvent.Leave:
                print("mouse leaved %s" % obj.objectName())    
            return super(window_b, self).eventFilter(obj, event)
    

    If you only need to change the style, you can simply use the pseudo-state “:hover” in a stylesheet (from the designer, or in the constructor with self.setStyleSheet):

    QPushButton {
         border: 1px solid black;   
         padding: 5px;
    }
    QPushButton:hover {   
        border: 1px solid black;
        border-radius: 5px;   
        background-color:#66c0ff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a java swing GUI. Now I want to display a static
I have made a java program with GUI. Now I want to add a
I've made a gui in glade that I want to put in a python
i made an .xib file and added my buttons and labels. Then I created
So I made a Winforms GUI in Visual Studio using C#, but for the
I create an .app using py2app, and the GUI was made with pyqt4, and
I have GUI in Matlab that I have made using the Programmatic approach. It
So I am making a GUI to get tweets. I have made an event
I have made a java program with GUI and I want a stop button
I have made accelerators in my java gui by using setAccelerator(), and they work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.