QComboBox AbstractItemView::item

喜欢而已 提交于 2019-11-30 19:24:30

Your style sheet seemed correct, so I tried it. It seems the problem is similar to this one on Qt centre:

QCompleter sets a custom QAbstractItemDelegate on it's model and unfortunately this custom item delegate does not inherit QStyledItemDelegate but simply QItemDelegate (and then overrides the paintmethod to show the selected state).

If you replace the default delegate by a QStyledItemDelegate, your style sheet should work:

QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
combo->setItemDelegate(itemDelegate);

An alternative solution would be:

ui->comboBox->model()->setData(ui->comboBox->model()->index(-row-, 0), QSize(-width-, -height-), Qt::SizeHintRole);

, where -row- is zero-based item index; -width- and -height- stand for item width hint and height hint, respectively.

QComboBox::item worked for me

So for example, I was trying to change the color of the item when it was disabled, and the following code did the trick.

This one did not work:

QComboBox QAbstractItemView::item:!enabled {
    color:red;
}

Instead I used:

QComboBox::item:!enabled {
    color:red;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!