基类选择QMainWindow后全部控件disable的解决办法

近日创建QT工程的时候一个手抖
选择了QMainWindow基类而没有选择QWidget
结果造成了所有的控件都处于Disable的情况
并且将控件设置为enable也没有办法解决.
使用Label播放摄像头的时候,摄像头甚至变成了黑白…
还以为是摄像头坏了


解决办法为:
在ui_xxxxx.h文件里面找到:
centralWidget->setEnabled(false);
将false修改为true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来为您解答这些问题。 (1) 在QT平台中设计出显示出“HelloWorld! 你好 Qt!”字符串窗口的C++程序。 您可以按照如下代码编写您的程序: ```c++ #include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplication a(argc, argv); QLabel *label = new QLabel("HelloWorld! 你好 Qt!"); label->show(); return a.exec(); } ``` (2) 在上述程序中添加一个菜单栏和消息响应函数,功能为:显示一对话框“Click Me.”。 您可以按照如下代码修改您的程序: ```c++ #include <QApplication> #include <QLabel> #include <QMenuBar> #include <QMessageBox> int main(int argc, char *argv[]) { QApplication a(argc, argv); QLabel *label = new QLabel("HelloWorld! 你好 Qt!"); QMenuBar *menuBar = new QMenuBar(); QMenu *menu = new QMenu("菜单"); QAction *action = new QAction("Click Me.", menu); menu->addAction(action); menuBar->addMenu(menu); label->setMenuBar(menuBar); QObject::connect(action, &QAction::triggered, [=](){ QMessageBox::information(NULL, "Click Me.", "你点击了 Click Me."); }); label->show(); return a.exec(); } ``` (3) 添加垂直和水平布局,在布局中添加不同控件。 您可以按照如下代码修改您的程序: ```c++ #include <QApplication> #include <QLabel> #include <QMenuBar> #include <QMessageBox> #include <QVBoxLayout> #include <QHBoxLayout> #include <QPushButton> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget *widget = new QWidget(); QLabel *label1 = new QLabel("HelloWorld!"); QLabel *label2 = new QLabel("你好 Qt!"); QPushButton *button = new QPushButton("Click Me."); QVBoxLayout *vLayout = new QVBoxLayout(); QHBoxLayout *hLayout = new QHBoxLayout(); vLayout->addWidget(label1); vLayout->addWidget(label2); hLayout->addStretch(); hLayout->addWidget(button); hLayout->addStretch(); vLayout->addLayout(hLayout); widget->setLayout(vLayout); QObject::connect(button, &QPushButton::clicked, [=](){ QMessageBox::information(NULL, "Click Me.", "你点击了 Click Me."); }); widget->show(); return a.exec(); } ``` (4) 主基类选择QMainWindow,添加其他不同控件的消息响应函数。 您可以按照如下代码修改您的程序: ```c++ #include <QApplication> #include <QMainWindow> #include <QMenuBar> #include <QMessageBox> #include <QVBoxLayout> #include <QHBoxLayout> #include <QPushButton> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: QLabel *label1; QLabel *label2; QPushButton *button; private slots: void onButtonClicked(); }; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { label1 = new QLabel("HelloWorld!"); label2 = new QLabel("你好 Qt!"); button = new QPushButton("Click Me."); QVBoxLayout *vLayout = new QVBoxLayout(); QHBoxLayout *hLayout = new QHBoxLayout(); vLayout->addWidget(label1); vLayout->addWidget(label2); hLayout->addStretch(); hLayout->addWidget(button); hLayout->addStretch(); vLayout->addLayout(hLayout); QWidget *centralWidget = new QWidget(); centralWidget->setLayout(vLayout); setCentralWidget(centralWidget); QMenuBar *menuBar = new QMenuBar(); QMenu *menu = new QMenu("菜单"); QAction *action = new QAction("Click Me.", menu); menu->addAction(action); menuBar->addMenu(menu); setMenuBar(menuBar); connect(button, &QPushButton::clicked, this, &MainWindow::onButtonClicked); } MainWindow::~MainWindow() { } void MainWindow::onButtonClicked() { QMessageBox::information(this, "Click Me.", "你点击了 Click Me."); } int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } ``` 这样就完成了所有的要求。希望能帮到您!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值