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菜單