1
A
回答
2
通过调用addWidget()
方法的小部件添加到适当的地方,如:
ui->someLayout->addWidget(widgetToAdd);
只要确保你在你的主(UI)线程做到这一点。
0
您可以在运行时正常添加QRadioButtons,方法与运行前相同。 您可以动态创建QRadioButton并调用QFrame布局的addWidget方法。 如果你不能这样做,发布代码并让我给你看。
mainwindow.h
#include <QtGui/QMainWindow>
#include <QPushButton>
#include <QHBoxLayout>
#include <QRadioButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
QHBoxLayout * layout;
QPushButton * button;
public:
MainWindow(QWidget *parent = 0);
public slots:
void radioAdd();
};
mainwindow.cpp
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
layout = new QHBoxLayout(this);
QWidget * w = new QWidget(this);
w->setLayout(layout);
this->setCentralWidget(w);
button = new QPushButton(QString("push"),this);
layout->addWidget(button);
connect(button,SIGNAL(clicked()), this, SLOT(radioAdd()));
}
void MainWindow::radioAdd() {
QRadioButton * radio = new QRadioButton("Search from the &cursor", this);
layout->addWidget(radio);
}
的main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
在此代码的单选按钮获得在运行时创建(在槽函数radioAdd )。并在你的情况下,而不是将QRadioButton添加到wigdet布局,您将它们添加到QFrame中。
相关问题
- 1. 在运行时添加PictureBoxes
- 2. 在运行时向表中添加行
- 3. 在运行时添加和删除行
- 4. GridView在运行时逐行添加
- 5. 与QRadioButtons
- 6. 从QTableWidget组中的QRadioButtons行
- 7. 在运行时向TabLayout添加片段
- 8. Knockout在运行时添加子对象
- 9. 在运行时添加事件
- 10. 在ARC下运行时添加__strong ivar
- 11. 在运行时添加视图到ViewFlippers
- 12. 如何在运行时添加新列?
- 13. 如何添加代码在运行时
- 14. 添加项目RibbonDropDown在运行时
- 15. 在运行时添加属性
- 16. TFlowPanel。在运行时添加控件
- 17. Castle.DynamicProxy2并添加属性在运行时
- 18. 如何在运行时添加TextView?
- 19. ShieldUI Grid - 在运行时添加列
- 20. PDFBox在运行时添加新页面
- 21. GLUT:在运行时添加菜单项
- 22. 在添加类别时运行T4
- 23. 在运行时添加silverlight控件
- 24. Spring HibernateTemplate在运行时添加映射
- 25. 在运行时添加元素
- 26. Simpy:在运行时添加进程
- 27. 在运行时添加图标
- 28. 在运行时将TemplateField添加到GridView
- 29. 在运行时向GroupBox添加控件
- 30. 在运行时添加到strip菜单