QToolButton and Style sheet
Hi everybody,
Description
I have a QAction with an icon
the QAction is set in Qmenu with
Code:
menu->addAction(myAction)
on a widget inside the application, I have a QToolButton with the following code
Code:
myQToolButton->setDefaultAction(myAction)
this is done to have different access to the same action in different place
the style sheet is the following:
Code:
QToolButton#myQToolButton:hover{image: url(:/image_rollover);} QToolButton#myQToolButton:pressed{image: url(:/image_pushed);} QToolButton#myQToolButton:disabled{image: url(:/image_disabled);}
so the first question:
In understand that the QtoolButtoin is connected with the action but
how to remove the icon in QtoolButton to set correctly the style sheet inside?
So my second question relative to the first question:
If it's not possible to remove icon, How to set the style to an action inside a QMenu in order to get the same style to the Qmenu AND to the ToolButton
Thanks to all
David
Re: QToolButton and Style sheet
Do you have to use the stylesheet? Can't you use what QIcon offers?
Re: QToolButton and Style sheet
That's not so easy .... The whole application is based on Style sheet; some buttons change their pictures when they are toggled... others get differents states with different icones
it's more beautiful ... yes I know :rolleyes: not very useful... :D
Anyway if Qicon can make all states in rollover, pressed , disabled, and so an tell me, I will code for that ; but could you tell me how to do that...
Thanks
pozdrowienia !
David
Re: QToolButton and Style sheet
Take a look at QIcon::addPixmap and its parameters. You can add different pixmaps for different icon states.
Re: QToolButton and Style sheet
I test it in different case
but it seems that's not working for the "pushed mode" on not checkable buttons;
this is a property we use constantly, and it sems We should subclass mouseMoveEvent for a QToolButton and install and Event Filter
Somethings I don't want for just setting icones.
If I go on with style sheet, is there a way to subclass paintEvent in order to remove the iCon inside the QtoolButton and let go the style sheet through the QToolButton ,
it could be done, no ??? :cool:
Thanks for your help
David
Re: QToolButton and Style sheet
If you override paintEvent, you don't have to use stylesheets but instead do your completely custom painting based on your own set of icons.
Re: QToolButton and Style sheet
Ok , could you just post a little piece of code about that
Thanks
Re: QToolButton and Style sheet
Code:
if(...){
} else if(...){
} else ...
p.drawPixmap(rect(), px);
}
Re: [SOLVED]QToolButton and Style sheet
I find exactly What I have to do;
state are : Normal, Rollover, Pushed/on, Disabled
state not implemeneted are pushed mode.
In order to get an icone for different state, independant from the style
I do that:
Code:
icon.
addFile(":/Normal.png",
QSize(),
QIcon::Normal,
QIcon::Off);
// Normal icon.
addFile(":/Rollover.png",
QSize(),
QIcon::Active,
QIcon::Off);
//rollover icon.
addFile(":/Pushed.png",
QSize(),
QIcon::Active,
QIcon::On);
//pushed/On //disabled is already implemented
_myAction->setIcon(icon);
myToolButton->setDefaultAction(_undoAct);
In a subclass of QtoolButton, I override the paintEvent like that:
Code:
{
// case for pushed mode
if (isEnabled() && isDown())
{
initStyleOption(&opt);
// modify style Option: "icon", to get a new icon inside
p.
drawComplexControl(QStyle::CC_ToolButton, opt
);
}
else
QToolButton::paintEvent(e
);
// all other mode are supported
}
that'all :)
David