首页 > 解决方案 > 同一行有多个项目的 QT 组合框

问题描述

在此处输入图像描述

上面的按钮框在同一行上有多个项目。这是一个名为 Draftsight 的程序,用 QT 编写。

在此处输入图像描述

带有红色方块的按钮框是我所拥有的,但我需要更多信息在同一行..

有人知道如何实现这一目标吗?

我当前在同一组合框行中添加 2 个项目的代码:

//setup combobox :
QComboBox *colors = new QComboBox;
ui->toolBar_color->addWidget(colors);
colors->setMinimumWidth(150);

//routine to fill the combobox with external data :
colors->clear();
Dialog_color().extern_toolbar_load();
QPixmap pixmap(15,15);
for(int i = 0; i<red_list.size(); i++){
     pixmap.fill(QColor (red_list.at(i),green_list.at(i),blue_list.at(i)));
     colors->addItem(pixmap, comments.at(i));
}

所以实际上我需要这样的东西:

colors->addItem(pixmap, pixmap, pixmap, "text", "text");

有办法吗?

标签: c++qtuser-interfacecombobox

解决方案


感谢您的答复,

来解释red_list、green_list、blue list。这是用户在表格小部件中设置的 rgb 颜色值。如果从存储用户定义值的文本文件刷新,则在程序启动期间和程序执行期间加载 tablewidget 数据。该对话框尚未完成,但它按预期工作。

在此处输入图像描述

我也一直在考虑将几个像素图组合成一个长像素图,但它必须是一种自动组合所有 rgb 值和其他值(如线型等)的自动化方式。那么我怎样才能自动将几个像素图组合成一个.. 嗯,我必须考虑一下。

他们是如何使用 QT 设计器在 Draftsight 中做到这一点的?默认系统不会提供我认为的解决方案。

欢迎所有输入!

编辑,我找到了一个解决方案。当扩展功能示例时,它可以自动组合事物。到目前为止,我对解决方案感到满意。

如果 qt 可以为此进行更新。那样就好了。对于组合框,按下信号也可以代替使用事件过滤器。

在此处输入图像描述

//setup combobox..
QComboBox *test = new QComboBox;
ui->toolBar_layer->addWidget(test);
test->setMinimumWidth(150);
test->setMinimumHeight(20);
test->addItem("test item");
test->setIconSize(QSize(100, 15));

//setup picture template..
QPixmap pixmap(100, 15);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);

//contruct a picture based on rgb colors..
QPixmap pixmap_1(15,15);
pixmap_1.fill(QColor (255,0,0)); 
painter.drawPixmap(0, 0, 15, 15, pixmap_1);
//load pictures from file..
painter.drawPixmap(30, 0, 15, 15, QPixmap(":/icons/edit-paste.svg"));
painter.drawPixmap(60, 0, 15, 15, QPixmap(":/icons/terminal.svg"));
painter.end();

test->addItem(pixmap, "combobox");

推荐阅读