PDA

View Full Version : setitemchecked on QMenu



sgh
2nd June 2008, 09:51
hello,
i'v got one sample code and finished to build and it works fine now.
this code is used on qt3 library, but my working is on qt4.
so i tried to port my all codes from qt3 to qt4, rebuild it and result is ok.
i added menu for change my app theme, checking for menuitem isnt working.
i mean proper menuitem is always checking when im clicking it.
here is source code.


tools = new Q3PopupMenu( this, "toolsMenu" );

styleThemes = new Q3PopupMenu( this, "StyleThemes" );
id2007 = styleThemes->insertItem( tr("Office 2007"), this, SLOT(setOffice2007()) );
id2003 = styleThemes->insertItem( tr("Office 2003"), this, SLOT(setOffice2003()) );
styleThemes->setCheckable( TRUE );
styleThemes->setItemChecked(id2007, true);
styleThemes->setItemChecked(id2003, false);

tools->insertItem( QIcon( QPixmap(QString(IMAGE_PATH)+"menuIcons/styletheme.png") ),
tr("Themes"), styleThemes );


can you give me any suggestion for this issue?
thx.

vycke
2nd June 2008, 14:00
First of all, if you are porting to QT4, why are you still using the Q3PopupMenu class (instead of just QMenu)? Then you can just do setChecked() on the QAction item instead (but you'd have to use addAction() instead of insertItem()).


i mean proper menuitem is always checking when im clicking it.
I'm not exactly sure what you mean by this... When you click, the item you click gets checked? (this would be correct) Or are both functions getting called?

Vycke

sgh
3rd June 2008, 03:49
hi, vycke
i did try to use QMenu instead of Q3PopupMenu class, but i have a lot of code of this part.
so i continused to use this class(Q3PopupMenu).

I'm not exactly sure what you mean by this... When you click, the item you click gets checked? (this would be correct) Or are both functions getting called?
this screenshot help your understand.

vycke
3rd June 2008, 14:46
If you mean that both are always checked, I'm not sure how to solve that (except maybe use a QActionGroup).. If you mean that when you check one the other stays checked, the QActionGroup would solve that -- or you can do it programmatically in the slots (i.e. uncheck the one you didn't click).

I hope this helps, if not, maybe one of the experts here can help.

Vycke