繁体   English   中英

Mac OSX 中的样式 QComboBox

[英]Style QComboBox in Mac OSX

我在 Mac OSX 中设置 Qt5 的组合框弹出样式时遇到了一些问题

我的 QComboBox 样式表

QComboBox {
    font-size: 11px;
    height: 16px;
    padding: 1px 5px 1px 5px;
    border: 2px groove #4B4F4F;
    border-bottom: 2px ridge #424545;
    border-right: 2px ridge #424545;
    border-radius: 3px;
    color: #DEDEDE;
    background: qlineargradient(x1:0, x2:0, y1:0, y2:1, stop:0 #6B6E6E, stop:1 #595B5B);
}
QComboBox::drop-down {
    subcontrol-origin: padding;
    subcontrol-position: top right;
    width: 14px;
    border-left-width: 1px;
    border-left-color: #999999;
    border-left-style: solid; /* just a single line */
    border-top-right-radius: 3px; /* same radius as the QComboBox */
    border-bottom-right-radius: 3px;
}
QComboBox::down-arrow {
    height: 8px;
    width: 8px;
    image: url(:/resources/images/downarrow.png);
}
QComboBox:on {
    border: 1px solid #00A7CC;
    padding-left: 6px;
}
QComboBox QAbstractItemView {
    min-width: 100px;
    outline: 1px solid #808A8A;
    border: 1px solid #373838;
    selection-background-color: #808A8A;
    background-color: #4A4C4F;
}
QComboBox:!enabled {
    color: #909090;
}

Mac OSX 上的结果如下所示:

我想改变以下几点:

  • 去除弹出窗口顶部和底部的空白区域
  • 隐藏左侧的勾号或更改其大小

编辑:

我可以用空格解决问题,但不能用勾号解决。 看起来还是很丑的。

我将 QComboBox 的填充更改为:

QComboBox {
        padding: 0px 5px 0px 5px;
....

我仍然在左上角有一个小点,不知道如何隐藏它

我也想隐藏勾号,但 QStyleFactory 的解决方案效果不佳。 所以我解决了,我找到了另一个对我有用的解决方案:

ui->comboBox->setItemDelegate(new QStyledItemDelegate());

我有同样的问题,但仍然没有找到解决方案,所以我更改了样式工厂:

#if defined(Q_OS_MAC)
    ui->cb_action->setStyle(QStyleFactory::create("Windows"));
#endif

它适用于:

ui->cb_action->setStyle(QStyleFactory::create("Windows"));

...正如vic-lin所建议的那样。

在 SetStyleSheet 中添加以下行可能会解决您的问题,我遇到了同样的问题,但现在解决了。

combobox-popup: 0;

暂无
暂无

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

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