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. How set QGridLayout's fixed size?
Forum Updated to NodeBB v4.3 + New Features

How set QGridLayout's fixed size?

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 24.0k 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.
  • ValentinMicheletV Offline
    ValentinMicheletV Offline
    ValentinMichelet
    wrote on last edited by
    #2

    Hi Engelard,
    Did you try to use QSpacerItem?
    Also, maybe you could provide us with some code to better understand what you try to achieve as well as where and why it doesn't work.

    EngelardE 1 Reply Last reply
    2
    • ValentinMicheletV ValentinMichelet

      Hi Engelard,
      Did you try to use QSpacerItem?
      Also, maybe you could provide us with some code to better understand what you try to achieve as well as where and why it doesn't work.

      EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by
      #3

      @ValentinMichelet No. I just want simple set size function for Label, so i would tell where is exactly borders of that label should be. No code will help you because my question is in lowest level of simplicity. But if you rly need:

      topLayout = new QGridLayout(resultsDialog);
      

      Size of resultsDialog 350200, size of topLayout is same, and i wish resize it to 50150, but not with help of setMargins, i need it be at left top corner of a widget.

      1 Reply Last reply
      0
      • ValentinMicheletV Offline
        ValentinMicheletV Offline
        ValentinMichelet
        wrote on last edited by ValentinMichelet
        #4

        OK, I'm not sure to fully understand your needs nor to fully know how Qt layouts work behind the scene but here are some things I would try that may be helpful (at least I hope so) but that you maybe already tried yourself:

        • Try to create a UI file to better understand how parameters work
        • Play with layoutLeftMargin (yes, you can modify left, top and so on margins of your layout from the Designer)
        • Play with constraints policies of your widgets
        • Play with your label's alignment
        • Play with layoutSizeConstraint
        • Play with Spacers (horizontal and vertical)
        • Use style sheets to actually see the border of the label (this is only a debug purpose but may help better understand what is really happening)
        • Investigate how sizeHint mechanism works, for it may be resizing automatically things behind your back

        Also, instead of some code snippets, maybe you could provide us with some sort of mockup of what you try to achieve, so that I can try to replicate it with some code?

        EngelardE 1 Reply Last reply
        1
        • EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by
          #5

          I have to say that i really surprised, such simple and "first" thing that should be - is settingSize of object/widget/container, it must be an easyiest thing.

          1 Reply Last reply
          0
          • ValentinMicheletV ValentinMichelet

            OK, I'm not sure to fully understand your needs nor to fully know how Qt layouts work behind the scene but here are some things I would try that may be helpful (at least I hope so) but that you maybe already tried yourself:

            • Try to create a UI file to better understand how parameters work
            • Play with layoutLeftMargin (yes, you can modify left, top and so on margins of your layout from the Designer)
            • Play with constraints policies of your widgets
            • Play with your label's alignment
            • Play with layoutSizeConstraint
            • Play with Spacers (horizontal and vertical)
            • Use style sheets to actually see the border of the label (this is only a debug purpose but may help better understand what is really happening)
            • Investigate how sizeHint mechanism works, for it may be resizing automatically things behind your back

            Also, instead of some code snippets, maybe you could provide us with some sort of mockup of what you try to achieve, so that I can try to replicate it with some code?

            EngelardE Offline
            EngelardE Offline
            Engelard
            wrote on last edited by Engelard
            #6

            @ValentinMichelet said in How set QGridLayout's fixed size?:

            Play with layoutLeftMargin (yes, you can modify left, top and so on margins of your layout from the Designer)

            There is no such function, i told it when created this topic. And there is no possibility to use Designer since parent widget and layouts in it are created programmatically.

            For illustation, here is what i've got from simple code, as you can see, layout which contain 4 labels fit whole window:

            0_1540914335655_fufufu.jpg

            And size of my QGridLayout should be like that(red rect):

            0_1540914465666_fufufu.jpg

            1 Reply Last reply
            0
            • ValentinMicheletV Offline
              ValentinMicheletV Offline
              ValentinMichelet
              wrote on last edited by
              #7

              Again, I'm not sure to fully understand your problem (hence the mockup) so there may be simpler solutions.
              AFAIK, with only a dialog that has a grid layout and a label inside, your label will always be centered and the layout of the QDialog will occupy the entire size (hence the fact that your dialog and its layout are both 350x200). Now you can add spacers (horizontal and vertical) to push your label on the top left corner, right? Or do you really need to have a layout that is smaller than your QDialog? Also, are there other widgets inside your QDialog?

              EngelardE 1 Reply Last reply
              0
              • ValentinMicheletV ValentinMichelet

                Again, I'm not sure to fully understand your problem (hence the mockup) so there may be simpler solutions.
                AFAIK, with only a dialog that has a grid layout and a label inside, your label will always be centered and the layout of the QDialog will occupy the entire size (hence the fact that your dialog and its layout are both 350x200). Now you can add spacers (horizontal and vertical) to push your label on the top left corner, right? Or do you really need to have a layout that is smaller than your QDialog? Also, are there other widgets inside your QDialog?

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on last edited by
                #8

                @ValentinMichelet said in How set QGridLayout's fixed size?:

                Again, I'm not sure to fully understand your problem

                just added an illustrations with pictures

                1 Reply Last reply
                0
                • ValentinMicheletV Offline
                  ValentinMicheletV Offline
                  ValentinMichelet
                  wrote on last edited by ValentinMichelet
                  #9

                  @Engelard said in How set QGridLayout's fixed size?:

                  just added an illustrations with pictures

                  Yep, bad timing =) Thanks for the pictures!

                  There is no such function, i told it when created this topic.

                  I know, but what I did not know was you could not use the designer.

                  From your mockup, I'd go for QSpacerItem as well as setSizePolicy/setMinimumSize/setMaximumSize methods for the label.
                  Your QDialog layout's size will always fit your QDialog's size AFAIK. But maybe I'm wrong, so I'll let other people answer this if they know more about it.

                  1 Reply Last reply
                  0
                  • EngelardE Offline
                    EngelardE Offline
                    Engelard
                    wrote on last edited by Engelard
                    #10

                    @ValentinMichelet said in How set QGridLayout's fixed size?:

                    I'd go for QSpacerItem as well as setSizePolicy/setMinimumSize/setMaximumSize methods for the label.

                    No! I'm still believing in Qt! That's impossible that there is no functionality for resizing. Btw, just tried that stuff, totally no effect:

                    0_1540915699536_qtttr.jpg

                    P.S. label setMinimumSize/setMaximumSize change nothing(

                    1 Reply Last reply
                    0
                    • EngelardE Offline
                      EngelardE Offline
                      Engelard
                      wrote on last edited by Engelard
                      #11

                      I don't know, should i report a bug or something, nothing working, setsizePolicies, setMinimumHeight of labels or layout, none of that function working, i tried like 20 functions already, what sense from all that stuff if it do no effect...

                      P.S. Here is the code, anybody can just insert it in your dummy project to try:

                          resultsDialog = new QDialog(this, Qt::MaximizeUsingFullscreenGeometryHint | 
                          Qt::WindowSystemMenuHint);
                          resultsDialog->setMinimumSize(300, 450);
                          resultsDialog->setWindowFlag(Qt::WindowCloseButtonHint, true);
                          resultsDialog->setModal(true);
                          resultsDialog->setWindowTitle("final output");
                          resultsDialog->show();
                      
                          topRegLB = new QLabel("Most often results from  '0'  scans:", resultsDialog);
                          firstRegLB = new QLabel("#1: ----", resultsDialog);
                          secondRegLB = new QLabel("#2: -----", resultsDialog);
                          thirdRegLB = new QLabel("#3: ------", resultsDialog);
                      
                          topLayout = new QGridLayout(resultsDialog);
                          topLayout->addWidget(topRegLB, 0, 0, 1, 2);
                          topLayout->addWidget(firstRegLB, 1, 0);
                          topLayout->addWidget(secondRegLB, 2, 0);
                          topLayout->addWidget(thirdRegLB, 3, 0);
                      
                      1 Reply Last reply
                      1
                      • EngelardE Offline
                        EngelardE Offline
                        Engelard
                        wrote on last edited by Engelard
                        #12

                        After two hours i finally found something useful.

                        using:

                        topLayout->setRowStretch(0 | 1 | 2 | 3, 25);
                        

                        with combination for some widgets in layout Qt::AlignTop gives proper result:

                        0_1540920893843_rowsfuck.jpg

                        But layout still enormously huge, so it still does'nt change a size.

                        1 Reply Last reply
                        0
                        • ValentinMicheletV Offline
                          ValentinMicheletV Offline
                          ValentinMichelet
                          wrote on last edited by ValentinMichelet
                          #13

                          Oh yeah, the rowStretch is important too, I forgot. But again, the size of the QDialog’s layout is the size of the QDialog itself. I don’t see how to change that. If anyone knows, I’m more than interested.
                          Would it be possible to use a child layout?

                          EngelardE 1 Reply Last reply
                          1
                          • ValentinMicheletV ValentinMichelet

                            Oh yeah, the rowStretch is important too, I forgot. But again, the size of the QDialog’s layout is the size of the QDialog itself. I don’t see how to change that. If anyone knows, I’m more than interested.
                            Would it be possible to use a child layout?

                            EngelardE Offline
                            EngelardE Offline
                            Engelard
                            wrote on last edited by
                            #14

                            @ValentinMichelet said in How set QGridLayout's fixed size?:

                            the size of the QDialog’s layout is the size of the QDialog itself.

                            This is probably the most important combination of words in whole topic, clarify alot.

                            ValentinMicheletV 1 Reply Last reply
                            1
                            • EngelardE Engelard

                              @ValentinMichelet said in How set QGridLayout's fixed size?:

                              the size of the QDialog’s layout is the size of the QDialog itself.

                              This is probably the most important combination of words in whole topic, clarify alot.

                              ValentinMicheletV Offline
                              ValentinMicheletV Offline
                              ValentinMichelet
                              wrote on last edited by
                              #15

                              @Engelard said in How set QGridLayout's fixed size?:

                              @ValentinMichelet said in How set QGridLayout's fixed size?:

                              the size of the QDialog’s layout is the size of the QDialog itself.

                              This is probably the most important combination of words in whole topic, clarify alot.

                              Along with

                              the layout of the QDialog will occupy the entire size (hence the fact that your dialog and its layout are both 350x200).

                              and

                              Your QDialog layout's size will always fit your QDialog's size AFAIK.

                              Which are essentially three different ways to express the same idea ;)

                              1 Reply Last reply
                              2

                              • Login

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