void tst_QActionGroup::separators()
{
    QMainWindow mw;
    QMenu menu(&mw);
    QActionGroup actGroup(&mw);

    mw.show();

#ifdef QT_SOFTKEYS_ENABLED
    // Softkeys add extra "Select" and "Back" actions to menu by default.
    // Two first actions will be Select and Back when softkeys are enabled
    int numSoftkeyActions = 2;
#else
    int numSoftkeyActions = 0;
#endif

    QAction *action = new QAction(&actGroup);
    action->setText("test one");

    QAction *separator = new QAction(&actGroup);
    separator->setSeparator(true);
    actGroup.addAction(separator);

    QListIterator<QAction*> it(actGroup.actions());
    while (it.hasNext())
        menu.addAction(it.next());

    QCOMPARE((int)menu.actions().size(), 2 + numSoftkeyActions);

    it = QListIterator<QAction*>(actGroup.actions());
    while (it.hasNext())
        menu.removeAction(it.next());

    QCOMPARE((int)menu.actions().size(), 0 + numSoftkeyActions);

    action = new QAction(&actGroup);
    action->setText("test two");

    it = QListIterator<QAction*>(actGroup.actions());
    while (it.hasNext())
        menu.addAction(it.next());

    QCOMPARE((int)menu.actions().size(), 3 + numSoftkeyActions);
}
void tst_Q3ActionGroup::separators()
{
    QMainWindow mw;
    Q3PopupMenu menu(&mw);
    Q3ActionGroup actGroup(&mw);

    mw.show();

    Q3Action *action = new Q3Action(&actGroup);
    action->setText("test one");
    actGroup.addSeparator();

    actGroup.addTo(&menu);
    QCOMPARE((int)menu.count(), 2);

    actGroup.removeFrom(&menu);
    QCOMPARE((int)menu.count(), 0);

    action = new Q3Action(&actGroup);
    action->setText("test two");
    actGroup.addTo(&menu);
    QCOMPARE((int)menu.count(), 3);
}
示例#3
0
void tst_QActionGroup::separators()
{
    QMainWindow mw;
    QMenu menu(&mw);
    QActionGroup actGroup(&mw);

    mw.show();

    QAction *action = new QAction(&actGroup);
    action->setText("test one");

    QAction *separator = new QAction(&actGroup);
    separator->setSeparator(true);
    actGroup.addAction(separator);

    QListIterator<QAction*> it(actGroup.actions());
    while (it.hasNext())
        menu.addAction(it.next());

    QCOMPARE((int)menu.actions().size(), 2);

    it = QListIterator<QAction*>(actGroup.actions());
    while (it.hasNext())
        menu.removeAction(it.next());

    QCOMPARE((int)menu.actions().size(), 0);

    action = new QAction(&actGroup);
    action->setText("test two");

    it = QListIterator<QAction*>(actGroup.actions());
    while (it.hasNext())
        menu.addAction(it.next());

    QCOMPARE((int)menu.actions().size(), 3);
}