我想将QLineEdit
添加到QTabWidget
,但我总是得到
分段故障,SIGSEGV
我是按照以下方式完成的:
QHBoxLayout *layout = new QHBoxLayout;
QWidget *Tab = new QWidget(ui->tabWidget);
ui->tabWidget->addTab(Tab, "Tab1");
Tab->setLayout(layout);
QLineEdit *lE = new QLineEdit();
lE->setObjectName("Text");
lE->setText("Hello");
ui->tabWidget->widget(0)->layout()->addWidget(lE);
这种方式适用于添加QPushButton
,但不知何故,它不适用于QLineEdit
。
您可以向单元格添加小部件
示例:
//
QWidget* pWidget = new QWidget();
QLineEdit* foo = new QLineEdit(this);
foo->setText("Edit");
QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
pLayout->addWidget(foo);
pLayout->setAlignment(Qt::AlignCenter);
pLayout->setContentsMargins(0, 0, 0, 0);
pWidget->setLayout(pLayout);
this->ui->myTable->setCellWidget(1, 1, pWidget);