Results 1 to 8 of 8

Thread: Set a ToolButton Hovered

  1. #1
    Join Date
    Dec 2008
    Location
    PUNE (INDIA)
    Posts
    49
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Set a ToolButton Hovered

    Hi all Experts ,
    I am developing an application in which I am trying to make it work like MS-Excel .
    My problem is , I am trying to set a particular QToolButton hovered on some particular Event.
    Is it possible to set a particular QToolButton in hovered state ?
    Need help to set a button hovered state.
    Just give me a Hint.
    Attached Images Attached Images
    Last edited by vajindarladdad; 11th August 2009 at 10:21. Reason: spelling error
    Thanks & Regards ,

    Vajindar Laddad .
    Trainee Developer.
    (INDIA).
    91+9325014248

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    u mean like this .. u have to change
    http://doc.trolltech.com/4.3/stylesh...#pseudo-states
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    Create a QHoverEvent manually and send it like this.
    Qt Code:
    1. QHoverEvent event(QEvent::HoverEnter, pos, pos);
    2. QApplication::sendEvent(TARGETWIDGET, &event);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2008
    Location
    PUNE (INDIA)
    Posts
    49
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    Hi ,
    I have already applied the stylesheets to the buttons & these are working fine when the Button is clicked , hovered , hovered but not Pressed , etc .

    My stylesheet is like this
    QString styleSheet = QString("QToolButton\
    {border: 1px solid %1; background-color: %2; border-radius: 4px;} \
    QToolButton:hover:!pressed{border-width: 1px; border-image: url(:/images/RibbonToolButtonHoverBk.png) 4 4 4 4 stretch stretch;}\
    QToolButton:hover:pressed{border-width: 1px; border-image: url(:/images/RibbonToolButtonPressedBk.png) 4 4 4 4 stretch stretch;}\
    ").arg(border.name()).arg(color.name());

    these stylesheets are working fine when working with mouse hover , mouse click.
    I just want to implement the same with keyBoard usage
    Thanks & Regards ,

    Vajindar Laddad .
    Trainee Developer.
    (INDIA).
    91+9325014248

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    can u set these stylesheets while keyPressEvent() occurs ..? but i think hover is only used on mouse event ... ! but can u change the pseudo state of button manually ..
    Last edited by wagmare; 11th August 2009 at 11:54.
    "Behind every great fortune lies a crime" - Balzac

  6. #6
    Join Date
    Dec 2008
    Location
    PUNE (INDIA)
    Posts
    49
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    Hello Sir ,
    the Stylesheets are applied to the buttons already & its working fine with mouse events.
    My requirement is to change the state i.e. from unselected button to the hovered button without moving mouse over it.
    The button should be in hovered state .

    In other words , just need to shift focus from one button to another when we press a arrow keys , like we set in other languages like setTabOrder() in HTML , setTabIndex()
    Thanks & Regards ,

    Vajindar Laddad .
    Trainee Developer.
    (INDIA).
    91+9325014248

  7. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    Quote Originally Posted by vajindarladdad View Post
    In other words , just need to shift focus from one button to another
    Setting focus is different from hovering. Did you try what I suggested ?

  8. #8
    Join Date
    Dec 2008
    Location
    PUNE (INDIA)
    Posts
    49
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set a ToolButton Hovered

    Hi All & YogeshGokul,
    I tried what you all suggested but it is still not working .
    I have attached a trial project in which i have created the object of QHoverEvent & invoking the event.
    Please... Please let me know where i am going wrong.

    This is the function where i want to make the QToolButton Hovered.
    Qt Code:
    1. void Widget::keyPressEvent(QKeyEvent *event)
    2. {
    3. QPoint newPos(toolButton->pos().x()+5,toolButton->pos().y()+10);
    4. QPoint oldPos(QCursor::pos());
    5.  
    6. qDebug("ToolButton Position %d %d",newPos.x(),newPos.y());
    7. qDebug("Cursor Position %d %d",oldPos.x(),oldPos.y());
    8.  
    9. QHoverEvent *hoverEvent = new QHoverEvent(QEvent::HoverEnter,newPos,oldPos);
    10. QApplication::postEvent(toolButton,hoverEvent);
    11.  
    12. qDebug("In Widget::keyPressEvent");
    13. QWidget::keyPressEvent(event);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Thanks & Regards ,

    Vajindar Laddad .
    Trainee Developer.
    (INDIA).
    91+9325014248

Similar Threads

  1. Toolbutton odd sizes
    By andytork in forum Qt Programming
    Replies: 0
    Last Post: 21st January 2009, 06:25
  2. how exclusive toolbutton in toolbar
    By irmakci in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2008, 22:33
  3. Dockwidget and Toolbutton
    By sandeepvl in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 07:23

Tags for this Thread

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.