QT对齐最重要的内容在Combobox中

发布于 2025-01-27 04:26:07 字数 520 浏览 2 评论 0原文

我正在与QT合作,为我正在从事的小型游戏理论项目创建GUI。我正在使用Combobox作为团队的选择者。我可以很好地对齐下拉窗口中的内容,例如,

for(int i = 0; i < ui.comboBox->count(); i++)
{
    ui.comboBox->setItemData(i, Qt::AlignLeft, Qt::TextAlignmentRole);
}

我无法弄清楚如何对齐所选择的顶部项目,因为您可以看到在这里。内容不在左侧对齐,名称甚至脱离屏幕。有人知道我如何将其与下拉列表中的内容相似吗?

我已经在网上搜索了,但是我在正确的措辞上遇到了麻烦。此外,如果我在键入ui.combobox-&gt;时浏览AutoCompleter可用的选项,我真的看不到可以做我想做的选择。

I am working with Qt to create a GUI for a small game theory project I'm working on. I'm using a combobox as a selector for the team. I can align the contents in the dropdown window just fine, e.g.

for(int i = 0; i < ui.comboBox->count(); i++)
{
    ui.comboBox->setItemData(i, Qt::AlignLeft, Qt::TextAlignmentRole);
}

I can't figure out how to align the top item that is selected, as you can see here. The contents is not aligned to the left and the name even goes off the screen. Does anyone know how I can align this similarly to the contents in the dropdown list?

I already searched online, but I'm having trouble phrasing the question correctly. Furthermore if I go through the options available to me by the autocompleter when typing ui.combobox-> I don't really see an option that can do what I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还在原地等你 2025-02-03 04:26:07

不确定这是否是修复的,但是我通过为ComboBox设置图标大小来解决它。我认为出了问题是,无论添加项目时图标的大小如何,可能都有一些默认的大小。我的图标尺寸为50x15,因此我添加了以下几行:

QSize size(50, 15);
ui.comboBox->setIconSize(size);

现在它正确完成并提供了正确的视图。

“正确视图”

Not sure if this is the go to fix, but I solved it by setting an icon size for the combobox. What I think goes wrong is that there is probably some default size set, no matter the size of the icons when adding items. My icons were of size 50x15 and so I added the following lines:

QSize size(50, 15);
ui.comboBox->setIconSize(size);

Now it is done correctly and gives the correct view.

the correct view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文