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. Not getting desired alignment of Widgets in QGridLayout

Not getting desired alignment of Widgets in QGridLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 460 Views 3 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I have following code

    class myConfig: public QWidget
    {
    Q_Object;
    public:
    myConfig();

    }

    myConfig::myConfig()
    {
    d_checkBox = new QCheckBox("Use Fill Pattern");

    QPushButton* defaultButton = new QPushButton(tr("Reset Colors"));

    // Max threshold limit
    QLabel* maxThresholdLabel = new QLabel(tr("Use Fill Pattern "));
    maxThresholdLabel->setMaximumWidth(100);
    QDoubleSpinBox* maxThresholdSpinBox = new QDoubleSpinBox();
    maxThresholdSpinBox->setMaximumWidth(75);
    maxThresholdLabel->setBuddy(maxThresholdSpinBox);
    maxThresholdSpinBox->setSingleStep(0.05);
    maxThresholdSpinBox->setMinimum(0);
    maxThresholdSpinBox->setMaximum(INT_MAX);
    maxThresholdSpinBox->setDecimals(2);

    QGridLayout* layout = new IN_CURRENT_POOL QGridLayout;
    layout->addWidget(d_fillCheckBox, 11, 0);
    layout->addWidget(defaultButton, 11, 1);

    // Max threshold limit
    QLabel* maxThresholdLabel = new IN_CURRENT_POOL QLabel(tr("Move Size "));
    maxThresholdLabel->setMaximumWidth(100);
    QDoubleSpinBox* maxThresholdSpinBox = new IN_CURRENT_POOL QDoubleSpinBox();
    maxThresholdSpinBox->setMaximumWidth(75);
    maxThresholdLabel->setBuddy(maxThresholdSpinBox);
    maxThresholdSpinBox->setSingleStep(0.05);
    maxThresholdSpinBox->setMinimum(0);
    maxThresholdSpinBox->setMaximum(INT_MAX);
    maxThresholdSpinBox->setDecimals(2);

    QGridLayout* layout = new IN_CURRENT_POOL QGridLayout;
    layout->addWidget(d_colorTreeWidget, 0, 0, 10, 2);
    layout->addWidget(d_fillCheckBox, 11, 0);
    layout->addWidget(defaultButton, 11, 1);
    layout->addWidget(maxThresholdLabel, 12, 0,1,10,0);
    layout->addWidget(maxThresholdSpinBox, 12,1,Qt::AlignLeft);
    setLayout(layout);

    }

    I have maxThresholdLabel and maxThresholdSpinBox should be side by side in last row and there should be very little space between the two widgets . I am not getting desired results with above code. I am getting layout as follows

    https://postimg.org/image/mna9f66tl/966e5907/

    Could you please suggest how to get max Threshold Label and maxThresholdSpinBox side by side with very little space between them

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

      Hi,

      Looks like QFormLayout might fit the bill.

      Hope it helps.

      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