StyleSheet & QComboBox, height trouble
-
Hi everyone,
this feels like I had the situation before, but for the life of me, I can't remember how to fix it.
I want to applay custom Stylesheet to a standart QComboBox, but I find myself unable to change the height of the items inside the popup QAbstractItemView.
I would like them to be at least 50 px tall.
Here's my stylesheet:"QComboBox{" "border: 0px;" "color:rgb(87,117,131);" "background-color: white;" "}" "QComboBox::drop-down{" "border: 0px;" "}" "QComboBox::down-arrow {" "image: url(:/data/GenericIcons/SpinDown.png);" "width:50px;" "height:50px;" "padding-right:38px;" "}" "QComboBox QAbstractItemView {" "border: 2px solid darkgray;" "selection-background-color: lightgray;" "color:rgb(87,117,131);" "}" "QComboBox QAbstractItemView::item {" "min-height: 50px;" "}"
I assumed, that
QComboBox QAbstractItemView::item
would adress the items of the popup, but no matter what I write there, it does not seem to have any effect.any tip is appreciated.
-
@J.Hilk
the reason why no stylesheet gets applied is, that the combobox's list view has a special delegate assigned (QComboBoxDelegate
) which just inheritsQItemDelegate
but notQStyledItemDelegate
.I don't know if it works, but you can try to assign your custom delegate to the combobox's list view. But IIRC that also comes with some visual side effects, so you would need to style the whole list view i guess.
-
Hi
It does respond to Qt::SizeHintRole
cb.model()->setData(cb.model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole); -
Well, thanks all for the help,
@raven-worx said in StyleSheet & QComboBox, height trouble:
the reason why no stylesheet gets applied is, that the combobox's list view has a special delegate assigned (QComboBoxDelegate) which just inherits QItemDelegate but not QStyledItemDelegate.
Well, it's not that no stylesheet is applied, this part
"QComboBox QAbstractItemView {" "border: 2px solid darkgray;" "selection-background-color: lightgray;" "color:rgb(87,117,131);" "}"
works absolutely fine, and if I give it a min-height it is applied, but it is applied to the whole view. The min-height of the items stays the same.
@mrjj said in StyleSheet & QComboBox, height trouble:
It does respond to Qt::SizeHintRole
cb.model()->setData(cb.model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);I tried it (just after the creation) but it does not seem to have any effect, I would have to look further into that.
@Devopia53 said in StyleSheet & QComboBox, height trouble:
like this:
comboBox->setView(new QListView);Well, color me surprised this is actually the solution! By giving the QCombobox a new QListView after creation I'm now able to access the Items of the QAbstractItemView, via StyleSheet.
The only question is, why is it not the default behaviour!?
Thank you very much @Devopia53 !
Btw, I kown now, how I solved this before. It's been a while that I worked on this project and I finally remembered. I made a complete custom Widget with from the bottom up sliding, tumbler-esc selection method.
It's horrible implemented on my part, but to be consitent with the rest of the program, I'll probably end up using it.
Thanks everyone for your time and help!
-
-I tried it (just after the creation) but it does not seem to have any effect, I would have to look further into that.
Well it has to have items and you need to set on each.
QAbstractItemModel* model = ui->comboBox->model();
auto rows = model->rowCount(QModelIndex());
for (int i = 0; i < rows; ++i) {
QModelIndex index = model->index(i, 0);
model->setData(index, QSize(50, 50), Qt::SizeHintRole);
} -
@J.Hilk said in StyleSheet & QComboBox, height trouble:
Well, it's not that no stylesheet is applied, this part
"QComboBox QAbstractItemView {"
"border: 2px solid darkgray;"
"selection-background-color: lightgray;"
"color:rgb(87,117,131);"
"}"works absolutely fine, and if I give it a min-height it is applied, but it is applied to the whole view. The min-height of the items stays the same.
Sure you can style the view itself.
I said the delegate (=> items) do not get a stylesheet applied.How do you add items to your combobox exactly?
-
@raven-worx said in StyleSheet & QComboBox, height trouble:
How do you add items to your combobox exactly?
very simply with
void QComboBox::addItems(const QStringList &texts)
-