转载别人的~QT5 mainwindow添加控件
来源:互联网 发布:dw制作淘宝首页 编辑:程序博客网 时间:2024/05/15 16:49
今天在QMainWindow添加控制,无法显示,加上布局管理器后也一样,到底为何?
首先,对于QDialog而言,添加控件过程:
1、创建子窗口部件,如
QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
2、创建一个布局
2、创建一个布局
QVBoxLayout *vbox = new QVBoxLayout;
3、将子窗口部件添加到布局中去
vbox->addWidget(radio1);
4、将布局设置到QDialog中去
this->setLayout(vbox);
这样,在Qdialog就可以看到子窗口部件了;但在QMainWindow中看不到???
求助google、百度,从QT Assistant 中找到这句话:
Note: Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.
原来mainwindow必须要有个centralWidget.于是便给他一个widget。示例代码如下:
QWidget *centerWindow = new QWidget;
this->setCentralWidget(centerWindow);
button1 = new QPushButton("One");
button2 = new QPushButton("Two");
button3 = new QPushButton("Three");
button4 = new QPushButton("Four");
button5 = new QPushButton("Five");
Note: Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.
原来mainwindow必须要有个centralWidget.于是便给他一个widget。示例代码如下:
QWidget *centerWindow = new QWidget;
this->setCentralWidget(centerWindow);
button1 = new QPushButton("One");
button2 = new QPushButton("Two");
button3 = new QPushButton("Three");
button4 = new QPushButton("Four");
button5 = new QPushButton("Five");
layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);
QGroupBox *groupBox = new QGroupBox(tr("登录"));
groupBox->setLayout(layout);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(groupBox);
centerWindow->setLayout(mainLayout);
groupBox->setLayout(layout);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(groupBox);
centerWindow->setLayout(mainLayout);
0 0
- 转载别人的~QT5 mainwindow添加控件
- 在mainwindow中通过代码添加控件
- Qt在mainwindow下代码添加控件不能显示的问题
- QT中在MainWindow中代码添加控件
- 转载别人的经验
- 转载别人的东西,。!
- 转载别人的文章
- Qt mainWindow添加状态栏,菜单栏,工具栏的Action方法
- Qt mainWindow添加状态栏,菜单栏,工具栏的Action方法
- QT5 学习之路11---MainWindow 简介
- 转载别人的一篇文章
- 转载:别人使用的工具
- 转载别人的正则表达
- 转载别人的笔记,内容丰富。
- 如何转载别人的博客
- 如何转载别人的博客
- 如何转载别人的文章
- 怎么转载别人的博客!!!
- mysql创建数据库后出现Access denied for user 'root'@'%' to database 'xxx'
- Leetcode OJ :Reverse Integer
- Android 活动主题Theme
- javaSE基本语法
- Python字典的遍历方法
- 转载别人的~QT5 mainwindow添加控件
- 图像用户界面GUI
- 数据处理流程
- [BZOJ2721][Violet 5]樱花(数论)
- Javaweb开发学习笔记(一)
- 任何n分频逻辑功能都可以由n分频使能来代替
- jquery mobile相关
- Android框架
- 们--加强斐波那契