简体   繁体   English

如何在一个合并的单元格中设置多个复选框?

[英]How to set multiple checkboxes in one merged cell?

I need to set multiple checkboxes in one merged cell in order to have them side by side or one under another (doesn't matter).我需要在一个合并的单元格中设置多个复选框,以使它们并排或一个在另一个下方(没关系)。 Now they overlap each other when I try.现在当我尝试时它们相互重叠。

Here the piece from the code:这是代码中的一段:

QTableWidget* my_table;
...
my_table->setSpan(0, 2, 2, 2);
...
my_table->setCellWidget(0,2, new QCheckBox("First"));
my_table->setCellWidget(1,2, new QCheckBox("Second"));

在此处输入图片说明

You have to create a QWidget with a layout (horizontal or vertical), and then add the checkboxes to the layout, something like this:您必须创建一个具有布局(水平或垂直)的 QWidget,然后将复选框添加到布局中,如下所示:

QWidget *widget = new QWidget();
QHBoxLayout *horizontalLayout = new QHBoxLayout(widget);
QCheckBox *cb = new QCheckBox(widget);
cb->setText("First");
QCheckBox *cb2 = new QCheckBox(widget);
cb2->setText("Second");
widget ->layout()->addWidget(cb); //adding to layout the first checkbox
widget ->layout()->addWidget(cb2);//adding to layout the second checkbox

//Your code
my_table->setCellWidget(1,2, widget);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM