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. QHboxLayout , how to put buttons and checkbox side by side
QtWS25 Last Chance

QHboxLayout , how to put buttons and checkbox side by side

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 3.1k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on 24 Apr 2016, 08:40 last edited by
    #1

    I have a requirement in which I have to place the buttons and check boxes side by side .For that I am using following code

    /* creating the refresh button/checkbox at the bottom widget*/
    QWidget* bottomWidget = new QWidget;
    QHBoxLayout layout = new IN_CURRENT_POOL QHBoxLayout;
    bottomWidget->setLayout(layout);
    QPushButton
    button1 = new IN_CURRENT_POOL QPushButton("Button1");
    QCheckBox* checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox");
    QCheckBox *checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox2");

    button1->setMaximumWidth(80);
    

    checkBox1->setMaximumWidth(120);
    controlsLayout->addWidget(button1);
    controlsLayout->addWidget(checkBox1);
    controlsLayout->addWidget(checkBox2);

    To place it side by side I am using following code as shown above

    button1->setMaximumWidth(80);
    checkBox1->setMaximumWidth(120);

    Is ther any other better way to achieve the requirement "I have to place the buttons and check boxes side"

    K 1 Reply Last reply 24 Apr 2016, 12:17
    0
    • Q Qt Enthusiast
      24 Apr 2016, 08:40

      I have a requirement in which I have to place the buttons and check boxes side by side .For that I am using following code

      /* creating the refresh button/checkbox at the bottom widget*/
      QWidget* bottomWidget = new QWidget;
      QHBoxLayout layout = new IN_CURRENT_POOL QHBoxLayout;
      bottomWidget->setLayout(layout);
      QPushButton
      button1 = new IN_CURRENT_POOL QPushButton("Button1");
      QCheckBox* checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox");
      QCheckBox *checkBox1 = new IN_CURRENT_POOL QCheckBox("CheckBox2");

      button1->setMaximumWidth(80);
      

      checkBox1->setMaximumWidth(120);
      controlsLayout->addWidget(button1);
      controlsLayout->addWidget(checkBox1);
      controlsLayout->addWidget(checkBox2);

      To place it side by side I am using following code as shown above

      button1->setMaximumWidth(80);
      checkBox1->setMaximumWidth(120);

      Is ther any other better way to achieve the requirement "I have to place the buttons and check boxes side"

      K Offline
      K Offline
      koahnig
      wrote on 24 Apr 2016, 12:17 last edited by
      #2

      @Qt-Enthusiast said:

      QPushButton button1 = new IN_CURRENT_POOL QPushButton("Button1");

      This is not a pointer! This should give already a compile error.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on 24 Apr 2016, 15:14 last edited by
        #3

        Sorry it was a typo I mean
        QPushButton* button1 = new IN_CURRENT_POOL QPushButton("Button1");

        If you could answer my question

        K K 2 Replies Last reply 24 Apr 2016, 15:35
        0
        • Q Qt Enthusiast
          24 Apr 2016, 15:14

          Sorry it was a typo I mean
          QPushButton* button1 = new IN_CURRENT_POOL QPushButton("Button1");

          If you could answer my question

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 24 Apr 2016, 15:35 last edited by
          #4

          @Qt-Enthusiast
          If I understand correctly what you want to achieve, I'd use a horizontal spacer to eat up the space instead of setting the maximum size for the elements. Something along the lines of:

          controlsLayout->addWidget(button1);
          controlsLayout->addWidget(checkBox1);
          controlsLayout->addWidget(checkBox2);
          controlsLayout->addStretch(1);
          

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • Q Qt Enthusiast
            24 Apr 2016, 15:14

            Sorry it was a typo I mean
            QPushButton* button1 = new IN_CURRENT_POOL QPushButton("Button1");

            If you could answer my question

            K Offline
            K Offline
            koahnig
            wrote on 24 Apr 2016, 15:38 last edited by
            #5

            @Qt-Enthusiast

            Sorry I thought you had an error when compiling.

            I do not see a better solution.

            Without going into detail it looks pretty similar to the documentation.. Another possibly to check things is also to use designer and check the files generated by meta compiler.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            1/5

            24 Apr 2016, 08:40

            • Login

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