Solved QComboBox, why the gap in the border?
-
I don't have any styles specified for the combo, however I will check now.
-
@SPlatten
But it looks very styled ?
I mean its not looking like the normal Qt one so i assumed you had use a stylesheet of sorts? -
I just checked by inserting:
const QString strStyles = pcboNew->styleSheet();
After the combo is created, the string returned is empty and there are no styles added, could the styles be inherited from the window?
-
@SPlatten
Yes, stylesheets affects all children too.
If stylesheet have a broad selector like
QWidget, then combobox would also be affected.you can try
ui->pcboNew->setStyleSheet(QLatin1String("QComboBox {\n" " border: 1px solid gray;\n" " border-radius: 3px;\n" " padding: 1px 18px 1px 3px;\n" " min-width: 6em;\n" "}\n" ""));
and see if line is still broken.
-
Any suggestion on how I find out whats effecting it?
Perhaps call styleSheet on the window?
-
@SPlatten
Try for test apply the showed stylesheet.
Also where do you apply a stylesheet ?
and how does it look ? -
@mrjj said in QComboBox, why the gap in the border?:
ui->pcboNew->setStyleSheet(QLatin1String("QComboBox {\n"
" border: 1px solid gray;\n"
" border-radius: 3px;\n"
" padding: 1px 18px 1px 3px;\n"
" min-width: 6em;\n"
"}\n"
""));I just copied and applied your style sheet and that fixed it, still puzzled why it is broken without that insert.
-
@SPlatten
Oh, it was not a fix. just a test.
Something in the master stylesheet is affecting the combobox as well.
Maybe some text margin setting that makes an item cover the line or similar.
Its often a result of use too broad selectors in the sheet so other widgets than the intended is affected.
http://doc.qt.io/qt-5/stylesheet-examples.html -
Works great thank you for your help, I've modified the XML parser to parse type specific CSS and add to the object:
<combo id="cbo1" x="150" y="10" width="80" properties="QComboBox { border: 1px solid black; border-radius: 2px; padding: 1px 18px 1px 3px; min-width: 6em}"> <item text="Item 1" value="123"/> <item text="Item 2" value="456"/> <item text="Item 3" value="789"/> </combo>
The appearance now:
-
@SPlatten
Ok, super. You might not need all tags. (like min-width: 6em)
but if you are fine with look. no harm to it.
Please use the Topic Tools button to mark as Solved. -
The idea is to make it as flexible as possible, the look of this is just a demonstration.
-
@SPlatten
Ok. if main app always have stylesheet then i see no harm.
However, if no style sheet is used in main app. it might make combobox look odd
for an un-styled app.