【问题标题】:Style QComboBox in Mac OSXMac OSX 中的样式 QComboBox
【发布时间】:2015-07-20 15:27:30
【问题描述】:

我在 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;
....

我的左上角还有一个小点,不知道如何隐藏它

【问题讨论】:

    标签: c++ macos qt qtstylesheets


    【解决方案1】:

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

    combobox-popup: 0;
    

    【讨论】:

      【解决方案2】:

      它适用于:

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

      ... 由 vic-lin 建议。

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

        • 这是一个比使用其他操作系统风格更好的解决方案
        【解决方案4】:

        我也有同样的问题,但还是没有找到解决办法,所以我改变了样式工厂:

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

        【讨论】:

          猜你喜欢
          • 2017-04-03
          • 2014-01-24
          • 2011-05-02
          • 2012-08-25
          • 2022-01-21
          • 1970-01-01
          • 1970-01-01
          • 2015-07-08
          • 2013-05-07
          相关资源
          最近更新 更多