Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox, why the gap in the border?

QComboBox, why the gap in the border?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    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:
    0_1542912260500_Screen Shot 2018-11-22 at 18.36.43.png
    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);
            }
    

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      HI
      Are you sure that effect does not come from the stylesheet?

      1 Reply Last reply
      0
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        I don't have any styles specified for the combo, however I will check now.

        Kind Regards,
        Sy

        mrjjM 1 Reply Last reply
        0
        • SPlattenS SPlatten

          I don't have any styles specified for the combo, however I will check now.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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?

          1 Reply Last reply
          1
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            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?

            Kind Regards,
            Sy

            mrjjM 1 Reply Last reply
            0
            • SPlattenS SPlatten

              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?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @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.

              1 Reply Last reply
              2
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                Any suggestion on how I find out whats effecting it?

                Perhaps call styleSheet on the window?

                Kind Regards,
                Sy

                mrjjM 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  Any suggestion on how I find out whats effecting it?

                  Perhaps call styleSheet on the window?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @SPlatten
                  Try for test apply the showed stylesheet.
                  Also where do you apply a stylesheet ?
                  and how does it look ?

                  1 Reply Last reply
                  0
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #9

                    @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.

                    Kind Regards,
                    Sy

                    mrjjM 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @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.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @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

                      1 Reply Last reply
                      1
                      • SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by SPlatten
                        #11

                        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:
                        0_1542921015793_Screen Shot 2018-11-22 at 21.09.37.png

                        Kind Regards,
                        Sy

                        mrjjM 1 Reply Last reply
                        0
                        • SPlattenS SPlatten

                          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:
                          0_1542921015793_Screen Shot 2018-11-22 at 21.09.37.png

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @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.

                          1 Reply Last reply
                          0
                          • SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on last edited by
                            #13

                            The idea is to make it as flexible as possible, the look of this is just a demonstration.

                            Kind Regards,
                            Sy

                            mrjjM 1 Reply Last reply
                            0
                            • SPlattenS SPlatten

                              The idea is to make it as flexible as possible, the look of this is just a demonstration.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @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.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved