Qt中的菜单项启用/禁用

时间:2013-01-22 05:56:02

标签: qt qt4

在下面的代码我想, 如果我选择/单击患者类型按钮。他们在菜单“xmenumain”“小儿心电图”项目应该被禁用(它应该在菜单列表中列出,但颜色为褪色灰色)。我该如何实现它?

void MyMenu::cppSlot()
    {
     xmenumain = new QMenu;

    xmenumain->addAction("                   X",this, SLOT (call_exit(xmenumain)));
    xmenumain->addAction ( "Edit User Settings" , this , SLOT (call_a()) );
    xmenumain->addAction ( "Parameters" , this , SLOT (call_b()) );
    xmenumain->addAction ( "Sound Adjust" , this , SLOT (call_c()) );
    xmenumain->addAction ( "Patient Type" , this , SLOT (call_d()) );
    xmenumain->addAction ( "Pediatric ECG" , this , SLOT (call_d()) );
    xmenumain->addAction ( "Data Output" , this , SLOT (call_d()) );
    xmenumain->addAction ( "Set Time & Date" , this , SLOT (call_d()) );
    xmenumain->addAction ( "Sweepspeed" , this , SLOT (call_d()) );
    xmenumain->addAction ( "Respspeed" , this , SLOT (call_d()) );

    //xmenumain->popup( QCursor::pos() );
    //Change font and width

    xmenumain->setFont(QFont ("Courier", 13));
    xmenumain->setFixedWidth(250);
    //Colour setting
    QPalette palette=xmenumain->palette();
    palette.setColor(QPalette::Background, Qt::darkGray);
    xmenumain->setPalette(palette);
    //xmenumain->languageChange();


    //xmenumain->setAutoFillBackground(true);


    // Align the menu coordinates
    xmenumain->move(940,370);
    xmenumain->show();
    /*if(!(xmenumain->isEnabled()))
    {
        xmenumain->show();
    }*/
}

1 个答案:

答案 0 :(得分:8)

你应该有一个QAction对象:

QAction *action = new QAction("Pediatric ECG");
connect(action, SIGNAL(triggered), this, SLOT(...));
action->setEnabled(false);

xmenumain->addAction(action);