2 Attachment(s)
QComboBox text alignment via CSS, and QComboBox ListItem Height
Hi All,
I've two little trouble with my QComboBox that make me crazy.
The first one, is that i would like to right align the selected item text via CSS inside QComboBox.(like the behavior of the QSpinBox).
Attachment 11166
I tried, more or less, everything inside my css but seems impossible to do. :(
This is my current CSS:
Code:
border: 1px solid darkgray;
border-radius: 0px;
padding-right: 20px;
min-width: 6em;
color: black;
}
selection-color: rgb(0, 150, 200);
background: white;
}
subcontrol-origin: padding;
subcontrol-position: top right;
width: 15px;
height: 30px;
border-width: 0px;
border-left-width: 1px;
border-left-color: darkgray;
border-left-style: solid; /* just a single line */
border-top-right-radius: 0px; /* same radius as the QComboBox */
border-bottom-right-radius: 0px;
}
image: url(:/images/icons/caret-down_262626_16.png);
}
top: 0px;
left: 0px;
background: rgb(0, 150, 200);
}
/* background-color: rgb(0, 150, 200);
border-radius: 0px;*/
selection-background-color:white ;
selection-color:rgb(0,150,200) ;
}
The second question is regarding the items in the QComboBox list. Is possible, still through CSS, to set height of those items?
More in detail, i would like to increase the space between the items. How you can see from the picture below, the height is the same of each item.
Attachment 11167
Thanks a lot for any suggestion.
Re: QComboBox text alignment via CSS, and QComboBox ListItem Height
Ok, i found an workaround(unfortunately seems there is no way to do this by css)... and it's not so bad.
I created a custom class that inherited from QComboBox.
Then in the constructor i set the QComboBox editable and put the related QLineEdit disabled.
Setting the QLineEdit property readOnly = true and the correct right alignment(Qt::AlignRight) did the trick.
Below is attached the code. (For someone, like me, that became crazy for this stupid behavior).
Code:
#include "customcombobox.h"
#include <QLineEdit>
{
this->setEditable(true);
this->lineEdit()->setDisabled(true);
this->lineEdit()->setReadOnly(true);
this->lineEdit()->setAlignment(Qt::AlignRight);
}