Having an image and text in a QComboBox (QSS)
-
I'm trying to display a little image inside the text field of a QComboBox like this:
QComboBox#folderSelectionComboBox { image: url(:Images/folderIcon.svg); image-position: left; }This works, but the text overlays the icon:

I tried adding apadding: 2 2 2 20;but that moves the text AND the image.
Is there a way to move just the text in the box? -
Hi
Im not sure we can move the text.What about
QLineEdit* lineEdit = ui->combo->lineEdit();
lineEdit->setClearButtonEnabled(true);
lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition); -
Hi
Im not sure we can move the text.What about
QLineEdit* lineEdit = ui->combo->lineEdit();
lineEdit->setClearButtonEnabled(true);
lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition); -
@mrjj Hm, lineEdit() keeps returning NULL, that's odd.
Edit: Ah, the CBox has to be editable. I'll try that real quick.
@qwasder85
Sorry my bad. ( i didnt check docs)
"Only editable combo boxes have a line edit."
so if its not editable ( its a property ) then it returns null. -
@qwasder85
Sorry my bad. ( i didnt check docs)
"Only editable combo boxes have a line edit."
so if its not editable ( its a property ) then it returns null. -
Hi
Im not sure we can move the text.What about
QLineEdit* lineEdit = ui->combo->lineEdit();
lineEdit->setClearButtonEnabled(true);
lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);@mrjj said in Having an image and text in a QComboBox (QSS):
lineEdit->setClearButtonEnabled(true); lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);Both of these lines are cheating! It's not a "clear" button, and the docs also state the clear button is traling. Aren't you ashamed of yourself? ;-)
-
@mrjj said in Having an image and text in a QComboBox (QSS):
lineEdit->setClearButtonEnabled(true); lineEdit->addAction(":/:Images/folderIcon.svg", QLineEdit::LeadingPosition);Both of these lines are cheating! It's not a "clear" button, and the docs also state the clear button is traling. Aren't you ashamed of yourself? ;-)