[Qt-interest] Using QStyleSheet to Restyle Checkable Menu Items

Scott Aron Bloom Scott.Bloom at onshorecs.com
Fri Sep 17 17:24:47 CEST 2010


After some further investigation... the stylesheet example has a
checkbox modification example... Here is the relevant code from the
stylesheet.

QMenu::indicator {
    width: 13px;
    height: 13px;
}

QMenu::indicator:unchecked {
    image: url(:/images/checkbox_unchecked.png);
}

QMenu::indicator:unchecked:hover {
    image: url(:/images/checkbox_unchecked_hover.png);
}

QMenu::indicator:unchecked:pressed {
    image: url(:/images/checkbox_unchecked_pressed.png);
}

QMenu::indicator:checked {
    image: url(:/images/checkbox_checked.png);
}

QMenu::indicator:checked:hover {
    image: url(:/images/checkbox_checked_hover.png);
}

QMenu::indicator:checked:pressed {
    image: url(:/images/checkbox_checked_pressed.png);
}


Create a string containing that information (the size needs to be bigger
to look good in the QMenu) create your images and put them in your .qrc
file), then call qApp->setStyleSheet
 

The 

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Friday, September 17, 2010 7:43 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Using QStyleSheet to Restyle Checkable Menu
Items

First, I would play in the Designer, and use the "setStyleSheet" to get
it to work... http://doc.trolltech.com/4.6/stylesheet-designer.html

For a QMenu, you need to modify the ::indicator subcontrol
http://doc.trolltech.com/4.6/stylesheet-reference.html#list-of-sub-contr
ols

I would recommend, you have a checked and unchecked image (rather than
custom painting), so you would be modifying the :checked and non-checked
states of the menu.

I would also look at the setStyleSHeet example that comes with Qt

Scott
-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Jake Colman
Sent: Friday, September 17, 2010 5:26 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Using QStyleSheet to Restyle Checkable Menu Items


I would like to restyle checkable menu items so that they display a
small checkbox that is red when checked and clear when unchecked.  With
Qt3 I used a QCustomMenuItem and a derived paint() method to precisely
render the size of the checkbox and the desired behavior.  With Qt4 it
appears that QStyleSheet is the way to go is ::indicator subcontrol.
But, although I have reviewed the relevant docs I am stymied as to how
to do this.  Can someone help me get started with something that
approximates what I am looking to do?

Thanks.

...Jake


-- 
Jake Colman | Director, Software Development
Principia Partners LLC
101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755 9770
t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221 8929
e: colman at ppllc.com | w: www.principiapartners.com
Credit technology innovation awards winner 2008 and 2009

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list