Qt-interest Archive, January 2007
QMenu (is_item_checked())
Message 1 in thread
I'm porting something from 3.3 to 4.2
In 3.3, I had a QPopupMenu which seemed to work. I had a function
decide if an item in the menu was checked or not. Now, either using a
Q3PopupMenu or QMenu, it works backwards. That's to say,
QMenu::isItemChecked(int i) returns FALSE when an item is checked, and
TRUE when it is not. The code below behaves properly, although you can
tell at a glance, it is backwards.
Should I just accept this as-is? It's ghetto, but works.
I check the 4.2 QMenu member function isItemChecked, and it tells me to
use QAction::isChecked instead. I really have no desire to bother w/ a
QAction at this point, as it works... although I did waste some time
figuring it out.
void myview::toggle( int t )
{
QMenu* m = (QMenu *)sender();
if ( m->isItemChecked(t) ) { // actually unchecked
cout << "unchecked: " << t << ", " << qPrintable(
m->text(t) ) << endl;
cout << "setting item to checked " << endl;
m->setItemChecked( t, TRUE );
} else { // actually checked
cout << "checked: " << t << ", " << qPrintable(
m->text(t) ) << endl;
cout << "setting item to unchecked " << endl;
m->setItemChecked( t, FALSE );
}
}
cheers
Paul
--
[ signature omitted ]