QComboBox, why the gap in the border?
-
I'm working on an application that will take the properties and configuration for each widget from an XML file. I have something odd going on with a QComboBox, in my XML file I have:
<combo id="cbo1" x="150" y="10" width="80"> <item text="Item 1" value="123"/> <item text="Item 2" value="456"/> <item text="Item 3" value="789"/> </combo>
The window properties are controlled by another XML definition, here is a screenshot of how this appears:
I don't understand why the border at the bottom of the combo has a section missing, I've tried just about everything I can think of but it still remains missing.The geometry for this widget is:
x1: 150, y1:10, x2:229, y2:39
There are no additional flags being specified for this widget...any ideas?
Here is the code that creates the combo box:
QComboBox* pcboNew = new QComboBox(pobjWin); lstOfNodes lstComboChildNodes = pobjChild->lstGetChildNodes(); foreach( clsXMLnode* pobjCboChild, lstComboChildNodes ) { QString strCboChildName = pobjCboChild->strGetNodeName(); if ( strCboChildName.compare(clsXMLnode::mscszNodeItem) == 0 ) { QString strText = pobjCboChild->strGetAttr(clsXMLnode::mscszAttrText) ,strValue = pobjCboChild->strGetAttr(clsXMLnode::mscszAttrValue); if ( strValue.isEmpty() != true ) { pcboNew->addItem(strText, QVariant(strValue)); } else { pcboNew->addItem(strText); } } else { pobjCboChild->intConnectSubscribers(static_cast<void*>(pcboNew)); } } QRect rctGeom = pcboNew->geometry(); if ( strX.isEmpty() != true ) { rctGeom.moveLeft(strX.toInt()); } if ( strY.isEmpty() != true ) { rctGeom.moveTop(strY.toInt()); } if ( strWidth.isEmpty() != true ) { rctGeom.setWidth(strWidth.toInt()); } if ( strHeight.isEmpty() != true ) { rctGeom.setHeight(strHeight.toInt()); } if ( rctGeom.isValid() == true ) { pcboNew->setGeometry(rctGeom); }
-
HI
Are you sure that effect does not come from the stylesheet? -
@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.
-
@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: