在QMainWindow添加控件无法显示而QDialog却可以
来源:互联网 发布:9块9包邮淘宝店 编辑:程序博客网 时间:2024/05/29 02:27
今天在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 mainwindow without a central widget isnot 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 mainwindow without a central widget isnot 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
- 在QMainWindow添加控件无法显示而QDialog却可以
- 在QMainWindow添加控件,无法显示问题
- 在使用 <s:iterator value="#request.students"></s:iterator> 无法显示数据,而 ${request.students[0].id} 却可以显示时问题
- 解决Tomcat可以在eclipse启动,却无法显示默认页面
- 解决Tomcat可以在eclipse启动,却无法显示默认页面
- jsp 编辑预览时样式可以显示出来,而在浏览器浏览时无法显示出来!
- QWidget QMainWindow QDialog
- QWidget、QMainWindow、QDialog区别
- QWidget、QMainWindow、QDialog区别
- QWidget,QMainWindow和QDialog
- QWidget、QMainWindow、QDialog区别
- QWidget、QMainWindow、QDialog区别
- 由于乱码而无法在putty显示出来的文件,可以这样删除或者重命名
- 使用draggablegridview开源库添加自定义控件可以显示,添加自定义的layout文件可以显示背景色但是无法显示其控件
- QWidget,QMainWindow和QDialog区别
- QWidget.QDialog.QMainWindow初步了解
- QWidget、QDialog、QMainWindow的区别
- QDialog QFrame QWidget QMainWindow区别
- 【微信6.0多开教程】iPhone不越狱如何安装多个微信?
- Delphi常用系统函数总结
- 用ClippingNode实现文字AVG游戏的对话字幕效果
- aes 256 java.security.InvalidKeyException
- C语言学习-1 字符串处理
- 在QMainWindow添加控件无法显示而QDialog却可以
- android tool export报错为support v7包问题
- App图标右上角的数字设置
- 解决Tomcat可以在eclipse启动,却无法显示默认页面
- 文本排版之----TextKit
- Java学习笔记 —— 11
- FragmentTabHost切换Fragment时避免重复加载UI(ViewPager切换Fragment时也适用)
- 利用两个栈模拟队列
- 笔试题