PDA

View Full Version : stylesheet with QAction in QToolBar



waiter
31st August 2012, 03:05
how to stylesheet with QAction in QToolBar,I want to change icon with the QActon,but I don't know how?
any help? please!

melody:p
31st August 2012, 10:01
What is you do?
If you want to change tool button icon when mouse over
you can use this code :


QIcon* icon = new QIcon;
icon->addPixmap(QPixmap(":/Images/normal"));
icon->addPixmap(QPixmap(":/Images/hover", QIcon::Active));
action->setIcon(*icon));


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 :


toolbar->installEventFilter(this);

bool hvMenuToolbarManager::eventFilter( QObject *obj, QEvent* e )
{
QAction* action;
QPoint pos;

switch( e->type() )
{
case QEvent::HoverMove:
pos = static_cast<QHoverEvent*>(e)->pos();
action = static_cast<QToolBar*>(obj)->actionAt(pos);
if(action)
{
action->setIcon(QIcon(":/Images/toolbar_icon"));
}
return true;

default:;
}

return QObject::eventFilter(obj, e);
}


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..

waiter
4th September 2012, 13:05
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