0

我是 Qt 的新手。就目前而言,我有一张带按钮的桌子btn。单击按钮时,setCentralWidget(view)将接管窗口,因此我再也看不到表格了。但是,如果我删除setCentralWidget(view),单击按钮时不会显示任何内容。

有没有办法可以在同一个窗口中显示两者?拆分或停靠?

(我删除了与我的问题无关的代码)

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);
}
4

2 回答 2

0

您应该查看QMdiArea类 - 它被设计用作可以有许多内部小部件的主窗口的中央小部件。它还具有多种布局样式 - 在该页面上向下滚动以查看示例。

希望有帮助!

于 2013-01-07T21:51:04.757 回答
0

你应该继承 QWidget。例如,制作您自己的 MyWidget 类。例如,此类将在拆分器中包含一个 QGraphicsView 和一个 QTabWidget。并在您的 MainWindow 中将中央小部件设置为 MyWidget 的一个实例。

于 2013-01-10T08:31:52.330 回答