Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QCheckBox is too high compared to QLabel.

    General and Desktop
    4
    10
    194
    Loading More Posts
    • 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
      stretchthebits last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 3
        • S
          stretchthebits @SGaist last edited by

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

          Pl45m4 Thank You 2 Replies Last reply Reply Quote 0
          • Pl45m4
            Pl45m4 @stretchthebits last edited by

            @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 Reply Quote 0
            • Thank You
              Thank You @stretchthebits last edited by

              @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 Reply Quote 0
              • S
                stretchthebits @Pl45m4 last edited by

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

                Pl45m4 1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  @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 Reply Quote 2
                  • Pl45m4
                    Pl45m4 @stretchthebits last edited by

                    @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 Reply Quote 0
                    • S
                      stretchthebits @Pl45m4 last edited by

                      @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 Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        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 Reply Quote 0
                        • First post
                          Last post