Qt를 처음 사용했습니다. 그대로, 버튼이있는 테이블이 있습니다 btn
. 버튼을 클릭하면 setCentralWidget(view)
이 창을 인계하므로 더 이상 테이블을 더 이상 볼 수 없습니다. 그러나 setCentralWidget(view)
을 제거하면 버튼을 클릭해도 아무 것도 표시되지 않습니다.MainWindow에 두 개의 위젯 표시
같은 창에 둘 다 표시 할 수있는 방법이 있습니까? 분할 또는 도킹 어쩌면?
(내 질문에 무관하다 내가 제거한 코드)
MainWindow::MainWindow()
{
//etc
packet = new QTabWidget;
setCentralWidget(packet)
}
//other code
void MainWindow::create(const QString &a)
{
QTableWidget* table = new QTableWidget;
int tabIndex = packet->addTab(table, a);
packet->setCurrentIndex(tabIndex);
table->setRowCount(1);
table->setColumnCount(2);
table->setHorizontalHeaderLabels(QString("a;Simulator").split(";"));"));
table->setItem(0,0,new QTableWidgetItem(a));
QPushButton *btn = new QPushButton("load", this);
connect(btn, SIGNAL(clicked()), this, SLOT(sim()));
table->setCellWidget(0,1, btn);
}
void MainWindow::sim()
{
QGraphicsScene* scene = new QGraphicsScene(QRect(-10, -10, 100, 50));
QGraphicsView* view = new QGraphicsView();
scene->addText("Network");
view->setScene(scene);
view->setGeometry(QRect(10, 10, 100, 50));
setCentralWidget(view);
}
스타일 nitpick : split()을 피하십시오. 'table-> setHorizontalHeaderLabels (QStringList() << "a"<< "시뮬레이터")' –