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?
Qt 6.11 is out! See what's new in the release blog

QComboBox, why the gap in the border?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 3.2k 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 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