c++ - 同一行有多个项目的 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");
有办法吗?
解决方案
感谢您的答复,
来解释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");
推荐阅读
- javascript - 使用不同的键创建对象
- python - 在特定字符串之后返回文本中的数字
- javascript - 正则表达式超过 10 个数字
- javascript - 如何使用 javascript 创建 HTML 文件
- java - BOX API - 让外部用户选择他们的文件,然后像 Dropbox 选择器一样以编程方式下载选定的文件
- jquery - jquery API 数据未正确更新 - 1 数字低
- java - 什么是 d:c,它在这个程序中做了什么,还有其他方法可以做到这一点吗?
- intellij-idea - IDEA - 取消静音一个断点
- excel - 数据验证列表从 VBA 运行宏
- c# - 双引号消息的 Bot Framework 错误网关