【问题标题】:QCombobox down arrow imageQCombobox 向下箭头图像
【发布时间】:2012-07-14 03:32:45
【问题描述】:

如何更改 Qcombobox 向下箭头的图像? 现在我正在使用这个 QSS 代码,但这不起作用,我无法删除向下箭头边框。

QComboBox
{
    border: 0px;
}

QComboBox::down-arrow
{   
    border: 0px;
    background-repeat: no-repeat;
    background-position: center center;
    background-image-width: 50px;
    border-image: url(./select-BG.png);
    heidth:50px;
    width:100px;
}

截图如下:

【问题讨论】:

    标签: c++ qt qtstylesheets


    【解决方案1】:

    这是一个很晚的答案,但我认为我在 Qt 论坛的某个地方找到了解决方案。

    当将边框设置为 0px 时,组合框箭头的整个样式似乎都被替换了。所以我使用QComboBox::drop-down 将边框设置为0x,然后使用QComboBox::down-arrow 定义自定义箭头。下面的代码显示了一个对无法正确更改文本的color 属性的奇怪错误的附加修复。

    QComboBox {
        color: black;
        font: 14px;
        padding: 1px 0px 1px 3px; /* This (useless) line resolves a bug with the font color */
    }
    
    QComboBox:focus {
        color: red;
    }
    
    QComboBox::drop-down 
    {
        border: 0px; /* This seems to replace the whole arrow of the combo box */
    }
    
    /* Define a new custom arrow icon for the combo box */
    QComboBox::down-arrow {
        image: url(Resources/DropDownArrow.png);
        width: 14px;
        height: 14px;
    }
    

    我希望有人可以使用此信息并使其发挥作用:-)

    【讨论】:

    • Resources/DropDownArrow.png 如何与 .qrc 文件结合使用? @FrozenTarzan
    • @AustinWitherow:这与您在 QSS 文件中处理资源的方式没有直接关系。由于我不知道自己的参考应该是什么样子,所以我请您搜索 QSS + .qrc 文件 :-)
    • 我可以通过在 qrc 文件中创建一个资源并在 qss 文件中像这样链接它来轻松做到这一点...github.com/buzzcoin-project/BUZZ/blob/master/src/qt/res/…
    【解决方案2】:

    箭头位于样式由::drop-down 子控件控制的按钮上。因此,要删除边框,您可以使用:

    QComboBox::drop-down 
    {
        border: 0px;
    }
    

    【讨论】:

    • 对我来说,这会删除整个按钮的外观。我猜是因为它覆盖了它之前拥有的任何图像属性。
    猜你喜欢
    • 2015-06-30
    • 2011-04-30
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多