如何在Qmainwindow中添加标签?我用了QtabWidget,程序没报错 但是不出结果??纠结啊!!!
dialog=QDialog()dialog.label1=QLabel("ARM")dialog.label2=QLabel("APC")dialog.tabwidge...
dialog=QDialog()
dialog.label1=QLabel("ARM")
dialog.label2=QLabel("APC")
dialog.tabwidge=QTabWidget()
dialog.tabwidge.addTab(dialog.label1,"tab1")
dialog.tabwidge.addTab(dialog.label2,"tab2")
dialog.text=QTextEdit(self.tr("中心工作区"))
dialog.mainLayout=QGridLayout(self)
dialog.mainLayout.setMargin(5)
dialog.mainLayout.setSpacing(5)
dialog.mainLayout.addWidget( dialog.tabwidge,0,0,)
dialog.mainLayout.addWidget( dialog.text,0,1,)
self.setCentralWidget(dialog)
中心窗口为什么不显示?? 展开
dialog.label1=QLabel("ARM")
dialog.label2=QLabel("APC")
dialog.tabwidge=QTabWidget()
dialog.tabwidge.addTab(dialog.label1,"tab1")
dialog.tabwidge.addTab(dialog.label2,"tab2")
dialog.text=QTextEdit(self.tr("中心工作区"))
dialog.mainLayout=QGridLayout(self)
dialog.mainLayout.setMargin(5)
dialog.mainLayout.setSpacing(5)
dialog.mainLayout.addWidget( dialog.tabwidge,0,0,)
dialog.mainLayout.addWidget( dialog.text,0,1,)
self.setCentralWidget(dialog)
中心窗口为什么不显示?? 展开
1个回答
推荐于2016-03-13
展开全部
首先,对于QDialog而言,添加控件过程:
1、创建子窗口部件,如
QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
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");
layout = new QVBoxLayout;
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);
1、创建子窗口部件,如
QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
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");
layout = new QVBoxLayout;
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);
追问
self.setCentralWidget(dialog)
我已经把Dialod设为中心窗口了啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询