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. Sizes of windows in a simple program

Sizes of windows in a simple program

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.9k 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.
  • tomyT tomy

    Hi all,

    Please take a look at this simple code:

    #include <QApplication>
    #include <QHBoxLayout>
    #include <QSlider>
    #include <QSpinBox>
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
    
        QWidget* windo = new QWidget;
        windo -> setWindowTitle("Enter Your Age");
    
        QSpinBox* spinBox = new QSpinBox;
        QSlider* slider = new QSlider(Qt::Horizontal);
        spinBox -> setRange(0, 130);
        slider -> setRange(0, 130);
    
        QObject::connect(spinBox, SIGNAL(valueChanged(int)),
                         slider, SLOT(setValue(int)));
        QObject::connect(slider, SIGNAL(valueChanged(int)),
                         spinBox, SLOT(setValue(int)));
    
        spinBox -> setValue(35);
    
        QHBoxLayout* layout = new QHBoxLayout;
        layout -> addWidget(spinBox);
        layout -> addWidget(slider);
        windo -> setLayout(layout);
    
        windo -> show();
    
        return app.exec();
    
    }
    
    

    The lines are obvious as for what they do. But my question is, what factor in general does determine the size of the window in these programs please?

    For instance, if you look the output window, you see that the word "Age" is covered. If we have a longer window that word will be shown correctly.

    0_1545125786409_Capture.PNG

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #3

    @tomy If you don't set the size explicitly it will be set so that the content is properly sized or (if you use designer) to what it is in designer. The title-bar of the window isn't drawn by Qt, it is up to OS or window manager used.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • tomyT Offline
      tomyT Offline
      tomy
      wrote on last edited by
      #4

      Thanks to both of you.
      So the best way to set size is via the sizeHint() function, yeah?

      Previously I had a page on Docs in which there were the names of all functions plus the way they can be used. I can't find that page now. Do you use it please?

      J.HilkJ 1 Reply Last reply
      0
      • tomyT tomy

        Thanks to both of you.
        So the best way to set size is via the sizeHint() function, yeah?

        Previously I had a page on Docs in which there were the names of all functions plus the way they can be used. I can't find that page now. Do you use it please?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #5

        @tomy said in Sizes of windows in a simple program:

        Thanks to both of you.
        So the best way to set size is via the sizeHint() function, yeah?

        Previously I had a page on Docs in which there were the names of all functions plus the way they can be used. I can't find that page now. Do you use it please?

        sizeHint is usually the way to go.

        That page is still there:
        0_1545208411124_bdaf311d-bfb3-4b63-b924-3c90edf0423a-image.png


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        tomyT 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          @tomy said in Sizes of windows in a simple program:

          Thanks to both of you.
          So the best way to set size is via the sizeHint() function, yeah?

          Previously I had a page on Docs in which there were the names of all functions plus the way they can be used. I can't find that page now. Do you use it please?

          sizeHint is usually the way to go.

          That page is still there:
          0_1545208411124_bdaf311d-bfb3-4b63-b924-3c90edf0423a-image.png

          tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by
          #6

          @J.Hilk
          Thanks so much.
          It's more than one hour I'm seeking that address on the Docs but failed to find it. I only find this. Sorry.
          Would you please tell me how you reached that address.

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

            Hi,

            Do you mean the QWidget documentation ?

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

            tomyT 1 Reply Last reply
            2
            • SGaistS SGaist

              Hi,

              Do you mean the QWidget documentation ?

              tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by tomy
              #8

              @SGaist
              Yeah, thanks.
              How did you get to that point, I mean, the steps, please?
              Whatever I searched, I couldn't find the way.

              Updated
              I used this function to the code, but still no changes!

              windo->setMinimumSize(60, 20);
              

              The length of the window won't change!

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

                The easiest is to go to the "all C++ classes" page and search there.

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

                tomyT 1 Reply Last reply
                0
                • SGaistS SGaist

                  The easiest is to go to the "all C++ classes" page and search there.

                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by
                  #10

                  @SGaist
                  I even can't find such a phrase either. My bad (or bad Doc).
                  From this point, what item do you click so that it takes you to "all C++ classes"?
                  I think you don't mean All Qt C++ Classes.

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

                    Look on the left side of the page. Under Reference.

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

                    tomyT 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Look on the left side of the page. Under Reference.

                      tomyT Offline
                      tomyT Offline
                      tomy
                      wrote on last edited by
                      #12

                      @SGaist
                      Sorry, there's no "all C++ classes" on my page but "All Qt C++ Classes", which doesn't go to this page.
                      Still it's mysterious how you could get access to the last mentioned page from the homepage of Docs!

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

                        Yes it's "All Qt C++ Classes" that I meant. It's just the intermediate step to go further and find the widget you want using a class "CTRL+F" search on the web page.

                        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
                        • tomyT Offline
                          tomyT Offline
                          tomy
                          wrote on last edited by tomy
                          #14

                          I can't find the page J.Hilk showed by the image and need to use your link to that page. That's it; that's Docs.

                          Anyway, I used the setMinimumSize function, as shown above, to the code but still no changes!

                          jsulmJ J.HilkJ 2 Replies Last reply
                          0
                          • tomyT tomy

                            I can't find the page J.Hilk showed by the image and need to use your link to that page. That's it; that's Docs.

                            Anyway, I used the setMinimumSize function, as shown above, to the code but still no changes!

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            @tomy Why don't you simply enter "QWidget" (or whatever you're looking for) in Google?

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            tomyT 1 Reply Last reply
                            0
                            • tomyT tomy

                              I can't find the page J.Hilk showed by the image and need to use your link to that page. That's it; that's Docs.

                              Anyway, I used the setMinimumSize function, as shown above, to the code but still no changes!

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on last edited by
                              #16

                              @tomy
                              you're using QtCreator right ? just write

                              QWidget w;
                              

                              place the curser inside the QWidget text block and press F1, you get the same page inside QtCreator you also get on the webpage

                              Otherwise here are the google coordinates:

                              • Search: QWidget
                              • Link Number: 1
                              • Link Text: QWidget Class | Qt Widgets 5.12 - Qt Documentation

                              to your question, 60;20 is super tiny have you tried it with something big, for example (200,200) to see a difference ?


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              1 Reply Last reply
                              2
                              • jsulmJ jsulm

                                @tomy Why don't you simply enter "QWidget" (or whatever you're looking for) in Google?

                                tomyT Offline
                                tomyT Offline
                                tomy
                                wrote on last edited by
                                #17

                                @jsulm
                                I thought when we are on Docs, everything inside that would be reachable through obvious steps.

                                @J.Hilk

                                place the curser inside the QWidget text block and press F1

                                It's the best, at least for the point where I am now. I try using it rather than Docs web page from now on.

                                I needed length to be longer, hence:
                                window->setMinimumSize(200, 40);
                                Even this couldn't alter the length until 200 was replaced by 250.
                                Now it's fine.

                                Thanks to all of you.

                                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