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 3486070
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:59:03+00:00 2026-05-18T10:59:03+00:00

how to implement mouseEnter and mouseLeave event in QWidget? if the mouseEnter to the

  • 0

how to implement mouseEnter and mouseLeave event in QWidget?

if the mouseEnter to the QWidget then i need to set the Background color into Gray,
if the mouseLeave from the QWidget then i need to set the background color is white

i tried

void enterEvent(QEvent *);
void leaveEvent(QEvent *);

in the inside of the enter&leave event i am using bool varibale set true & false. and i am calling the QPainter event update();

the code below:

void Test::enterEvent(QEvent *)
{
   _mouseMove=true;
    update();

}

void Test::leaveEvent(QEvent *)
{
   _mouseMove=false;
    update();

}

void Test::paintEvent(QPaintEvent *)
{
    QPainter painter;
    painter.begin(&m_targetImage);
    painter.setRenderHint(QPainter::Antialiasing);

        if(_mouseMove){
            painter.fillRect(QRect(0,0,width(),height()),Qt::white);}
        else{
            painter.fillRect(QRect(0,0,width(),height()),Qt::gray);}

    painter.end();

    QPainter p;
    p.begin(this);
    p.drawImage(0, 0, m_targetImage);
    p.end();
}

i am getting following error when i am moving the mouse in the QWidget

QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::end: Painter not active, aborted

Please help me to fix this. if any one having sample code please provide me….

  • 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-05-18T10:59:04+00:00Added an answer on May 18, 2026 at 10:59 am

    First I would use a member to save the current background color instead of a boolean. This will simplify the paintEvent code:

    painter.fillRect(QRect(...), m_backColor);
    

    I guess the errors appears for the first QPainter. Why are you using a QPainter to fill the image? If the var is a QImage you can use the fill function by example and the call drawImage as you do. You have the same kind of function for QPixmap.

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

Sidebar

Related Questions

To implement data access code in our application we need some framework to wrap
I need to implement a Diff algorithm in VB.NET to find the changes between
I need to implement version control, even for just the developing I do at
I've implemented a simple mouse listener where the background color changes whenever the mouse
I'm trying to implement a color picker in my Cocoa app. (Yes, I know
I am trying to implement the MyLocationOverlay class from google maps. However, when I
To implement a tab-based environment in WPF we need to convert our forms to
To implement a callback function from the native code to Java code, I have
I am looking to implement a mouseover event on my page for a menu
Task: implement paging of database records suitable for different RDBMS. Method should work for

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.