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

  • Home
  • SEARCH
  • 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 7979307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:44:36+00:00 2026-06-04T09:44:36+00:00

I am trying to implement a mouseover effect in Qt, but I don’t know

  • 0

I am trying to implement a mouseover effect in Qt, but I don’t know how to use the event handlers. I have created a simple Qt Widget Application with a pushButton. I am able to bind an event handler to the MainWindow like so:

MainWindow::enterEvent(QEvent *event)
{
    ui->pushButton_3->setGraphicsEffect(effect);
}

This works, the graphicsEffect is applied to the pushButton. But I don’t understand how to bind the event handler to a single QObject. As far as I know is it not possible to use signals, because they only support click events and no mouseover events.

I am pretty new to Qt and I was not able to find any information I could understand.

Can anyone explain to me how to bind an event handler to a single QObject?

Thanks in advance.

  • 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-04T09:44:37+00:00Added an answer on June 4, 2026 at 9:44 am

    I figured it out, in another way, by using the ‘Promote to …’ option in the QtCreator.
    As also explained here: http://sector.ynet.sk/qt4-tutorial/customing-widgets.html

    I added a class ‘MyPushButton”:

    mypushbutton.h

    #ifndef MYPUSHBUTTON_H
    #define MYPUSHBUTTON_H
    
    #include <QPushButton>
    #include <QGraphicsDropShadowEffect>
    
    class MyPushButton : public QPushButton
    {
        Q_OBJECT
    public:
        MyPushButton(QWidget *parent = 0);
    
    private:
        void enterEvent(QEvent *e);
        void leaveEvent(QEvent *e);
    
        QGraphicsDropShadowEffect *effect;
    };
    
    #endif // MYPUSHBUTTON_H
    

    mypushbutton.cpp

    #include "mypushbutton.h"
    
    MyPushButton::MyPushButton(QWidget *parent)
        :QPushButton(parent)
    {
        effect = new QGraphicsDropShadowEffect();
        effect->setBlurRadius(5);
        effect->setEnabled(false);
        this->setGraphicsEffect(effect);
    }
    
    void MyPushButton::enterEvent(QEvent *event)
    {
        if (this->isEnabled())
            effect->setEnabled(true);
    }
    
    void MyPushButton::leaveEvent(QEvent *event)
    {
        if (this->isEnabled())
            effect->setEnabled(false);
    }
    

    and then I right clicked my QPushButton in the editor and I selected ‘Promote to …’ and I added MyPushButton as ‘Promoted class name’.

    It works like a charm and is very easy to expand or customize as it works with any event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement a simple print in SL4. I have a DataGrid that I
Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
I have just started with jQuery. I am trying to implement zebra striping in
I'm trying to implement QAbstractItemModel for QTreeView. I have problem with inserting rows. I
I am trying to create a calendar instance. I have imported the java.util.calendar but
Trying to implement AVAudioplayer and get some metering data of the played music, but
I'm trying to implement a very simple way to select a subsection of the
Trying to implement the new FP 10.1 Global error handler into my projects but
I'm trying to implement a simple rollover tooltip for images on a page where

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.