为什么当我在qt中禁用按钮时,所有小部件都将被禁用?

时间:2016-10-05 13:05:33

标签: qt

使用qt时,我想禁用按钮或动作,所以我使用

ui.actionSave->setDisabled(disabled);
/*ui.actionSaveAs->setDisabled(disabled);
ui.actionRotate->setDisabled(disabled);
ui.actionFlipH->setDisabled(disabled);
ui.actionFlipV->setDisabled(disabled);
ui.cropBtn->setDisabled(disabled);*/

以及这些按钮和操作的关系是:

    void setupUi(QMainWindow *testClass)
{
    if (testClass->objectName().isEmpty())
        testClass->setObjectName(QStringLiteral("testClass"));
    testClass->resize(800, 800);
    actionOpen = new QAction(testClass);
    actionOpen->setObjectName(QStringLiteral("actionOpen"));
    actionSaveAs = new QAction(testClass);
    actionSaveAs->setObjectName(QStringLiteral("actionSaveAs"));
    actionSave = new QAction(testClass);
    actionSave->setObjectName(QStringLiteral("actionSave"));
    actionRotate = new QAction(testClass);
    actionRotate->setObjectName(QStringLiteral("actionRotate"));
    actionFlipV = new QAction(testClass);
    actionFlipV->setObjectName(QStringLiteral("actionFlipV"));
    actionFlipH = new QAction(testClass);
    actionFlipH->setObjectName(QStringLiteral("actionFlipH"));
    centralWidget = new QWidget(testClass);
    centralWidget->setObjectName(QStringLiteral("centralWidget"));
    imgLabel = new ImgLabel(centralWidget);
    imgLabel->setObjectName(QStringLiteral("imgLabel"));
    imgLabel->setGeometry(QRect(290, 220, 241, 241));
    imgLabel->setLayoutDirection(Qt::LeftToRight);
    imgLabel->setAutoFillBackground(true);
    imgLabel->setAlignment(Qt::AlignCenter);
    cropBtn = new QPushButton(centralWidget);
    cropBtn->setObjectName(QStringLiteral("cropBtn"));
    cropBtn->setGeometry(QRect(10, 30, 75, 23));
    testClass->setCentralWidget(centralWidget);
    menuBar = new QMenuBar(testClass);
    menuBar->setObjectName(QStringLiteral("menuBar"));
    menuBar->setGeometry(QRect(0, 0, 800, 23));
    menuFile = new QMenu(menuBar);
    menuFile->setObjectName(QStringLiteral("menuFile"));
    testClass->setMenuBar(menuBar);
    mainToolBar = new QToolBar(testClass);
    mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
    testClass->addToolBar(Qt::TopToolBarArea, mainToolBar);
    statusBar = new QStatusBar(testClass);
    statusBar->setObjectName(QStringLiteral("statusBar"));
    testClass->setStatusBar(statusBar);

    menuBar->addAction(menuFile->menuAction());
    menuFile->addAction(actionOpen);
    menuFile->addAction(actionSave);
    menuFile->addAction(actionSaveAs);
    menuFile->addSeparator();
    mainToolBar->addAction(actionSave);
    mainToolBar->addAction(actionRotate);
    mainToolBar->addAction(actionFlipV);
    mainToolBar->addAction(actionFlipH);

    retranslateUi(testClass);

    QMetaObject::connectSlotsByName(testClass);
} // setupUi

,结果如下: http://7xpoty.com1.z0.glb.clouddn.com/QQ%E6%88%AA%E5%9B%BE20161005211139.png

因此,此按钮将根据需要禁用,但其他按钮和菜单操作也将被禁用。 为什么会这样?任何建议将不胜感激,谢谢!

0 个答案:

没有答案