4

经过无数小时尝试设置 QComboBox 的样式后,我被插入项目的顶部和底部边距卡住了。

我想删除或应用背景颜色到弹出菜单顶部和底部的空白处。

QComboBox 屏幕 http://img576.imageshack.us/img576/3402/screenshot20120130at144.png

我向 QListView 添加了一个最小高度,以不显示顶部和底部箭头。我还查看了 Qt 源代码中的 QComboBoxPrivate 类,但似乎顶部和底部边距是硬编码的。

谢谢你的帮助。

编辑:到目前为止,这是我的样式表

QComboBox {
    border: 1px solid rgb(95, 95, 95);
    border-radius: 3px;
    padding: 1px 18px 1px 3px;
    min-width: 6em;
    color: rgb(220, 220, 220);
    background-color: rgb(80, 80, 80);
    margin: 0 0 0 0;
}

QComboBox:editable {
    background: rgb(80, 80, 80);
}

QComboBox:!editable {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                  stop: 0 rgb(51, 51, 51), stop: 0.4 rgb(39, 39, 39),
                                  stop: 0.5 rgb(32,32,32), stop: 1.0 rgb(38,38,38));;
}

QComboBox::drop-down:editable {
}

QComboBox:!editable:on {
}

QComboBox::drop-down:editable:on {
}

QComboBox:on { /* shift the text when the popup opens */
    padding-top: 3px;
    padding-left: 4px;
    background-color: rgb(80, 80, 80);
}

QComboBox::drop-down {
    subcontrol-origin: padding;
    subcontrol-position: center right;
    width: 15px; 
    right:3px;
    border-top-right-radius: 3px; /* same radius as the QComboBox */
    border-bottom-right-radius: 3px;
    background:none;
}

QComboBox::down-arrow {
    image: url(:/images/arrow-down-inverted.png);
    height: 10px;
}

QComboBox::down-arrow:on { /* shift the arrow when popup is open */
    top: 1px;
    left: 1px;
}

QListView#comboListView {
    background: rgb(80, 80, 80);
    color: rgb(220, 220, 220);
    min-height: 90px;
    margin: 0 0 0 0;
}

QListView#comboListView::item {
    background-color: rgb(80, 80, 80);
}

QListView#comboListView::item:hover {
    background-color: rgb(95, 95, 95);
}
4

3 回答 3

6

您需要在 中自QAbstractItemView定义QComboBox

QComboBox QAbstractItemView {
    margin-top: 0px;
    padding-bottom: 0px;
}
于 2012-08-29T20:28:38.643 回答
0

试试下面的样式表:

QComboBox {
  margin-top: 0px;
  margin-bottom: 0px;
}

这应该将边距设置为 0。这里也是对样式表的 qt 引用。

于 2012-01-30T18:29:20.257 回答
0

我发现删除白边距的解决方案是将组合框设置为只读。

QCombobox* choiceBox = new QCombobox;
choiceBox->lineEdit()->setReadOnly(true);
于 2012-02-20T13:11:10.040 回答