Results 1 to 3 of 3

Thread: Mouse Over Event on QPushButtons

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Question Mouse Over Event on QPushButtons

    Hi all

    I am working on Qt4.1 on my Intel MAC , I m having 5 buttons on my MainWindow and each button is represented by different Icon(image), What I wanted do is when mouse pointer is over the button it is replaced by the text,

    For this I Subclass QPushButton & Use enter and leave events functions ,Its also working but when mouse pointer entered the buttons it replaces the icon of everybutton with the same text , and on leaving it replaces the text of the button with the same icons

    But For each button I want the text & icon should be differnt.

    How can i do this

    How can i differentiate all the buttons.

    Thanx
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Mouse Over Event on QPushButtons

    Sounds to me like you're hardcoding the text and icon in the subclass. But these should be member variables of the object.

    Maybe you should post your code if this doesn't help you.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  3. The following user says thank you to Michiel for this useful post:

    merry (6th August 2007)

  4. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mouse Over Event on QPushButtons

    The simplest solution I can think of is this
    Qt Code:
    1. PushButton::PushButton( const QString & text, const QColor & color,
    2. QWidget * parent, const char* name )
    3. : QPushButton(parent, name)
    4. {
    5. _color = color;
    6. setText(text);
    7. mCustomToolTip = 0;
    8. setMouseTracking(true);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QColor& PushButton::getColor()
    2. {
    3. return _color;
    4. }
    To copy to clipboard, switch view to plain text mode 
    Then in CustomToolTip you can have this
    Qt Code:
    1. void CustomToolTip::paintEvent ( QPaintEvent * )
    2. {
    3. QPainter p(this);
    4. p.fillRect( rect(), Qt::transparent );
    5.  
    6. if( parentWidget() )
    7. {
    8. p.setBrush( ((PushButton*)parentWidget())->getColor() );
    9. p.drawEllipse(rect());
    10. p.drawText(rect(), Qt::AlignCenter, parentWidget()->name());
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    Hence there is no need for enterEvent and leaveEvent eventhandlers filters

  5. The following user says thank you to vermarajeev for this useful post:

    merry (6th August 2007)

Similar Threads

  1. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26
  2. Mouse over event
    By merry in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 11:13
  3. rotation and mouse event identification
    By kiransu123 in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2007, 04:41
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.