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. QCheckBox is too high compared to QLabel.

QCheckBox is too high compared to QLabel.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 571 Views
  • 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.
  • S Offline
    S Offline
    stretchthebits
    wrote on last edited by
    #1

    Allo,
    I am on Kubuntu 20.10.
    I have Qt Creator 4.14.2, it says based on Qt 5.15.2 (GCC 7.3.1 20180303 (Red Hat 7.3.1-5), 64 bit)

    I have a QCheckBox and a QLabel. They are both suppose to be on the same “line” if you know what I mean.
    Imagine that I draw a horizontal line on my window.
    I want to place a LABEL on the line and a little to right, I will place a CHECKBOX (with its own text).

    I use setGeometry for the QCheckBox and the QLabel to set their position and sizes.
    I also have a function that compares their height. If the height of QCheckBox is too little, it pushes it down.
    For example,
    If HeightOfCheckBox = 15 pixels
    If HeightOfLabel = 20 pixels
    Push down CheckBox by 5 pixels.

    So, in principle, they should be at the same level.
    I attached an image of what I get.1.png

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

      Hi,

      Why not use a QHBoxLayout ? It does what you want automatically.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

        Why not use a QHBoxLayout ? It does what you want automatically.

        S Offline
        S Offline
        stretchthebits
        wrote on last edited by
        #3

        @SGaist Ok, I tried it in there. It doesn’t show anything.

        layout=new QHBoxLayout(this);
        layout->addWidget(CHECKWordInserted);
        layout->addWidget(STATICWordInserted);
        layout->addWidget(EDITWordToInsert);
        QRect rect;
        rect.setX(CHECKWordInsertedPosSize[0]);
        rect.setY(CHECKWordInsertedPosSize[1]);
        rect.setWidth(CHECKWordInsertedPosSize[2]);
        rect.setHeight(CHECKWordInsertedPosSize[3]);
        layout->setGeometry(rect);
        

        Do I have to call setGeometry for CHECKWordInserted (which is a QCheckBox) and for STATICWordInserted and for EDITWordToInsert.
        Is the coordinate relative to the QHBoxLayout?

        Pl45m4P Thank YouT 2 Replies Last reply
        0
        • S stretchthebits

          @SGaist Ok, I tried it in there. It doesn’t show anything.

          layout=new QHBoxLayout(this);
          layout->addWidget(CHECKWordInserted);
          layout->addWidget(STATICWordInserted);
          layout->addWidget(EDITWordToInsert);
          QRect rect;
          rect.setX(CHECKWordInsertedPosSize[0]);
          rect.setY(CHECKWordInsertedPosSize[1]);
          rect.setWidth(CHECKWordInsertedPosSize[2]);
          rect.setHeight(CHECKWordInsertedPosSize[3]);
          layout->setGeometry(rect);
          

          Do I have to call setGeometry for CHECKWordInserted (which is a QCheckBox) and for STATICWordInserted and for EDITWordToInsert.
          Is the coordinate relative to the QHBoxLayout?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @stretchthebits said in QCheckBox is too high compared to QLabel.:

          . It doesn’t show anything.

          Did you forgot to add your layout to your mainLayout or set it as mainLayout if your widget had no layout already?

          No you usually dont need setGeometry when using layouts.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          S 1 Reply Last reply
          0
          • S stretchthebits

            @SGaist Ok, I tried it in there. It doesn’t show anything.

            layout=new QHBoxLayout(this);
            layout->addWidget(CHECKWordInserted);
            layout->addWidget(STATICWordInserted);
            layout->addWidget(EDITWordToInsert);
            QRect rect;
            rect.setX(CHECKWordInsertedPosSize[0]);
            rect.setY(CHECKWordInsertedPosSize[1]);
            rect.setWidth(CHECKWordInsertedPosSize[2]);
            rect.setHeight(CHECKWordInsertedPosSize[3]);
            layout->setGeometry(rect);
            

            Do I have to call setGeometry for CHECKWordInserted (which is a QCheckBox) and for STATICWordInserted and for EDITWordToInsert.
            Is the coordinate relative to the QHBoxLayout?

            Thank YouT Offline
            Thank YouT Offline
            Thank You
            wrote on last edited by
            #5

            @stretchthebits

            Maybe this will help
            `
            widgetInWhichYouWantLayout->setLayout(layout);

            // mainWidget->setLayout(layout);
            `

            Let's make QT free or It will go forever

            TRUE AND FALSE <3

            1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @stretchthebits said in QCheckBox is too high compared to QLabel.:

              . It doesn’t show anything.

              Did you forgot to add your layout to your mainLayout or set it as mainLayout if your widget had no layout already?

              No you usually dont need setGeometry when using layouts.

              S Offline
              S Offline
              stretchthebits
              wrote on last edited by
              #6

              @Pl45m4 Well, how else is it going to know that I want this layout thing to be positioned below the textbox (QLabel) "Copy character count (min 1 and max 3)"?
              I am not using layouts everywhere. I do all my positioning myself except there is this problem with the level of the checkbox text.

              This time, I added
              this->setLayout(layout);
              but again, I don't see it.

              Pl45m4P 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @stretchthebits said in QCheckBox is too high compared to QLabel.:

                layout=new QHBoxLayout(this);

                When you pass a parent to a layout, it is automatically applied to that parent.

                Positioning everything yourself is pretty rarely done. Properly using layouts, in your case, a combination of QVBoxLayout and QHBoxLayout or a QGridLayout will make things easier to maintain especially with screens of different resolutions.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • S stretchthebits

                  @Pl45m4 Well, how else is it going to know that I want this layout thing to be positioned below the textbox (QLabel) "Copy character count (min 1 and max 3)"?
                  I am not using layouts everywhere. I do all my positioning myself except there is this problem with the level of the checkbox text.

                  This time, I added
                  this->setLayout(layout);
                  but again, I don't see it.

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by
                  #8

                  @stretchthebits said in QCheckBox is too high compared to QLabel.:

                  except there is this problem with the level of the checkbox text.

                  A problem you wouldn't have when you use layouts everywhere :)
                  HBox and VBox Layouts will make your widgets allign properly in rows and columns.


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  S 1 Reply Last reply
                  0
                  • Pl45m4P Pl45m4

                    @stretchthebits said in QCheckBox is too high compared to QLabel.:

                    except there is this problem with the level of the checkbox text.

                    A problem you wouldn't have when you use layouts everywhere :)
                    HBox and VBox Layouts will make your widgets allign properly in rows and columns.

                    S Offline
                    S Offline
                    stretchthebits
                    wrote on last edited by
                    #9

                    @Pl45m4 OK I tried it in a test program and looks like it is able to align the text of a button and QCheckBox and a QLabel.
                    But how am I suppose to have control on the size of buttons and EDITBOXes?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Sounds like a QGridLayout.

                      Can you show a mock-up of what you want to achieve ? It would help us help you.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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