Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu item enable/disable in Qt

Tags:

qt

qt4

In the below code i want to , If i select / click Patient Type button. them in the menu "xmenumain" "Pediatric ECG" item should be disabled (it should list in the menu list but coloured in faded grey) . how do i achieve it ?

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();
    }*/
}
like image 608
kbk Avatar asked Oct 22 '25 14:10

kbk


1 Answers

You should have a QAction object:

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

xmenumain->addAction(action);
like image 112
hank Avatar answered Oct 26 '25 02:10

hank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!