Results 1 to 3 of 3

Thread: stylesheet with QAction in QToolBar

  1. #1
    Join Date
    Mar 2012
    Location
    china
    Posts
    54
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default stylesheet with QAction in QToolBar

    how to stylesheet with QAction in QToolBar,I want to change icon with the QActon,but I don't know how?
    any help? please!

  2. #2
    Join Date
    Jul 2012
    Posts
    23
    Thanks
    3

    Default Re: stylesheet with QAction in QToolBar

    What is you do?
    If you want to change tool button icon when mouse over
    you can use this code :
    Qt Code:
    1. QIcon* icon = new QIcon;
    2. icon->addPixmap(QPixmap(":/Images/normal"));
    3. icon->addPixmap(QPixmap(":/Images/hover", QIcon::Active));
    4. action->setIcon(*icon));
    To copy to clipboard, switch view to plain text mode 

    but you have to change icon in detail about mouse event,
    I recommend you that using event filter.

    before I know Qicon's function.. I tryed this method :
    Qt Code:
    1. toolbar->installEventFilter(this);
    2.  
    3. bool hvMenuToolbarManager::eventFilter( QObject *obj, QEvent* e )
    4. {
    5. QAction* action;
    6. QPoint pos;
    7.  
    8. switch( e->type() )
    9. {
    10. case QEvent::HoverMove:
    11. pos = static_cast<QHoverEvent*>(e)->pos();
    12. action = static_cast<QToolBar*>(obj)->actionAt(pos);
    13. if(action)
    14. {
    15. action->setIcon(QIcon(":/Images/toolbar_icon"));
    16. }
    17. return true;
    18.  
    19. default:;
    20. }
    21.  
    22. return QObject::eventFilter(obj, e);
    23. }
    To copy to clipboard, switch view to plain text mode 

    Of course, this code is not perfect, but it will be valuable attempt to you..

    and sadly, I don't know how to using stylesheet to toolbutton made by qactions... SORRY..
    Last edited by melody:p; 31st August 2012 at 09:10.

  3. #3
    Join Date
    Mar 2012
    Location
    china
    Posts
    54
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: stylesheet with QAction in QToolBar

    I know your way,but I want to use stylesheet .like QToolButton{qproperty-icon:url(:/PNG/1.png)},but I don't know how to specify the QAction

Similar Threads

  1. Open a window with a QAction in QToolBar
    By gen_mass in forum Newbie
    Replies: 4
    Last Post: 18th July 2010, 11:28
  2. how to add QAction vertically and horizontally in QToolBar
    By sanjayshelke in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2008, 09:56
  3. QToolBar and QAction
    By !Ci in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2008, 12:41
  4. QToolBar Stylesheet
    By guilugi in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2007, 11:47
  5. QAction
    By mickey in forum Qt Programming
    Replies: 7
    Last Post: 17th July 2006, 09:42

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.