1

最近我在这个问题中遇到了这样的问题,询问我如何才能将手放在 QComboBox 的 QScrollBar 上以改变其厚度。阅读回复后,我为我的 Qt Embedded 应用程序尝试了 Marco A. 解决方案,但没有成功。然后,为了测试,我将编译环境更改为 Desktop,修复成功!

所以基本上我的问题是,当我尝试在 Qt for Embedded Linux (ARM) 中更改 QComboBox 的 QScrollBar 宽度时,什么也没有发生,但是如果我为 Qt for Desktop 编译完全相同的代码,它就可以工作。以下是我用于测试的代码:

QAbstractItemView* poView = ui->comboBox->view();
QScrollBar* poBar = poView->verticalScrollBar();
poBar->setStyleSheet("width: 50px;");

还有另一个代码做同样的事情,但显示了同样的问题:

ui->comboBox->setStyleSheet("QScrollBar:vertical { width: 50px; }");

comboBoxQt Designer(在 Qt Creator 内部)中以 ui 形式声明。

Qt 版本对于 Desktop 和 Qt for Embedded Linux (4.8.5) 是相同的。我发现奇怪的另一件事(但应该与它无关)是再次为桌面编译相同的代码显示具有 Windows XP 样式的 QComboBox,而对于嵌入式则使用 Plastique 样式(我注意到由于 Plastique显示三个而不是两个按钮来滚动滚动条)。

那么可能会发生什么?我该如何解决这个问题?

4

2 回答 2

1

I noticed the same symptoms. In Qt a lot of the drawing, I understand, has been delegated to the styles, and the Plastique style seems to have a bug in that it doesn't seem to draw a vertical scroll bar in the right coordinates if it doesn't have the default size. So if you do this:

QScrollBar:vertical
{
    min-width: 35px;
    width: 35px;
}

you end up with the symptoms you described. But, AFAICS there's something wrong with the handling of margins as well! If you play around with the margins, e.g. like this:

QScrollBar:vertical
{
    min-width: 35px;
    width: 35px;
    margin-right: 35px;
}

you should be able to work around the bug.

Worked for me at least.

于 2015-01-20T14:07:25.217 回答
0
poBar->setMinimumWidth(50);
poBar->setMaximumWidth(50);

我在 Python3 语法中使用 PyQt5、QT5 进行了尝试,它在 Linux(Ubuntu 14.04)以及 windows7 上自定义了滚动条的宽度

于 2014-10-06T10:52:28.590 回答