[Qt-interest] context menu problem
Ankit Agarwal
ankit17.ag at gmail.com
Fri Dec 5 11:53:49 CET 2008
Hey thats a good way to try this out. Thanks a lot.
On Fri, Dec 5, 2008 at 4:10 PM, Benjamin <ikipou at gmail.com> wrote:
> In fact there is definitely a workaround to do this. You simply have
> to create a new QStyle for the menu, and change the color there.
> On mac, I subclass QMacStyle and override drawControl:
>
>
> void GreatStyle::drawControl ( ControlElement element, const
> QStyleOption * option, QPainter * painter, const QWidget * widget)
> const{
> if(element == QStyle::CE_MenuItem){
> const QStyleOptionMenuItem* menuOption = static_cast<const
> QStyleOptionMenuItem*>(option);
> if(menuOption->text == goodAction->text()){
> QStyleOptionMenuItem newMenuOption(*menuOption);
> QPalette newPalette(option->palette);
> newPalette.setColor(QPalette::ButtonText, QColor(255, 0, 0));
> newMenuOption.palette = newPalette;
> QMacStyle::drawControl(element, &newMenuOption, painter,
> widget);
> return;
> }
> }
> QMacStyle::drawControl(element, option, painter, widget);
> }
>
>
> where goodAction is the action I want in red. I set this new style to the
> menu:
> menu.setStyle(new RedStyle(importantAction, this));
>
> and this is it! Thanks to Andy Shaw for this great trick.
>
> 2008/12/4 Ankit Agarwal <ankit17.ag at gmail.com>:
> > Hi,
> > I have a context menu with 10 QMenu entries. Now, I want that out of
> those
> > 10 entries, 3 entries should be visible in red and rest in the default
> > colour. Please suggest how can i achive this.
> >
> > --
> > Regards,
> > Ankit Agarwal
> > SW Engineer
> > Vegayan Systems
> > email : ankit_agarwal at vegayan.com
> > Blog : http://ankit17.wordpress.com
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
>
--
Regards,
Ankit Agarwal
SW Engineer
Vegayan Systems
email : ankit_agarwal at vegayan.com
Blog : http://ankit17.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081205/5f0de390/attachment.html
More information about the Qt-interest-old
mailing list