Results 1 to 10 of 10

Thread: Mouse Over event on button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: Mouse Over event on button

    Thanks for that.

    But Actually I have created the buttons as

    QGroupBox *groupBox;
    QPushButton *PhotoRecoveryButton;
    QPushButton *CreateImageButton;

    CreateImageButton = new QPushButton(Dialog);
    CreateImageButton->setObjectName(QString::fromUtf8("CreateImageButto n"));
    CreateImageButton->setWindowModality(Qt::NonModal);
    CreateImageButton->setGeometry(QRect(30, 230, 131, 121));
    CreateImageButton->setCursor(QCursor(static_cast<Qt::CursorShape>(13 )));
    CreateImageButton->setMouseTracking(true);
    CreateImageButton->setFocusPolicy(Qt::StrongFocus);
    CreateImageButton->setIcon(QIcon(QString::fromUtf8(":/images/CreateImageLogical.png")));
    CreateImageButton->setIconSize(QSize(128, 128));
    CreateImageButton->setCheckable(true);
    CreateImageButton->setChecked(false);
    CreateImageButton->setAutoDefault(true);
    CreateImageButton->setDefault(true);
    CreateImageButton->setFlat(true);
    QWidget::setTabOrder(CreateImageButton, PhotoRecoveryButton);



    and I have make a SearchScanDiskDlg.h in which I have declare the

    protected:

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

    and then using these in .cpp file as

    void SearchScanDiskDlg::enterEvent(QEvent *event)
    {

    CreateImageButton->setIcon(QIcon(":/images/CreateImage1.png"));

    }



    void SearchScanDiskDlg::leaveEvent(QEvent *event)

    {

    CreateImageButton->setIcon(QIcon(":/images/CreateImageLogical.png"));

    }



    That is changes the icon on enterEvent and leaveEvent.

    It is changing the Icon only when I click somewhere on the Dialog
    I m sending you the form only to show u how it is looking.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Mouse Over event on button

    As the previous posts explain, you have to use the enter/leave events within the Button Class, so you have to create a custom class inheriting from QAbstractButton. What you have done so far, was to implement the enter-, leaveEvents of the dialog class. They have nothing to do with the buttons. If you are reluctant to introducing your own button class, there is a simpler solution that is more than sufficient for this task: Installing an event filter with QObject::installEventFilter() ...

    check the Qt-Docs for this. It's fairly simple.

  3. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Mouse Over event on button

    Thanks you to all.
    Now I m able to do this.

    Thanks.

Similar Threads

  1. Middle Button Mouse
    By jaime in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2006, 03:01
  2. Replies: 2
    Last Post: 24th July 2006, 18:36
  3. Draw QtCanvasElipse on mouse press event position
    By YuriyRusinov in forum Newbie
    Replies: 1
    Last Post: 31st May 2006, 11:57
  4. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 09:24
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.