QGroupBox sizing with my QT5 custom widget

115 views Asked by At

I am trying to make a custom widget: for displaying a processor register which has a name, a value and can be displayed in octal/decimal hexa. The code is shown at the bottom. I receive better result when I use the code as shown (i.e I insert QRadioButtons):

enter image description here

If I use

mainLayout->addWidget(DisplayMode);

instead (I guess this is the correct method) then the resulting picture is

enter image description here

Do I misunderstand something? What is wrong?

RegisterWidget::RegisterWidget(QWidget *parent)
:QFrame (parent)
{
  mValue = 0;
  mName = "";
  setFrameStyle(QFrame::Panel | QFrame::Sunken);    
  QHBoxLayout *mainLayout = new QHBoxLayout(this);
  label = new QLabel(tr("mName"),this);
  label->setText(mName);
  label->setLineWidth(2);   
  QGroupBox *DisplayMode = new QGroupBox("");
  QRadioButton *OctalR = new QRadioButton(this);
  QRadioButton *DecimalR = new QRadioButton(this);
  DecimalR->setChecked(true);    DecimalR->setDown(true);
  QRadioButton *HexaR = new QRadioButton(this);
  QHBoxLayout *hbox = new QHBoxLayout;
  hbox->addWidget(OctalR);
  hbox->addWidget(DecimalR);
  hbox->addWidget(HexaR);
  hbox->addStretch(1);
  DisplayMode->setLayout(hbox);
  mainLayout->addWidget(label);
  Value = new QLCDNumber(this);
  Value->setDigitCount(8);
  Value->setSegmentStyle(QLCDNumber::Flat);
  Value->display(mValue);
  mainLayout->addWidget(Value);
 /* mainLayout->addWidget(DisplayMode);*/ 
  mainLayout->addWidget(OctalR);
  mainLayout->addWidget(DecimalR);
  mainLayout->addWidget(HexaR);
  setLineWidth(3);
  setLayout(mainLayout); 
    connect(OctalR, SIGNAL(clicked()), this, SLOT(setOctal()));
    connect(DecimalR, SIGNAL(clicked()), this, SLOT(setDecimal()));
    connect(HexaR, SIGNAL(clicked()), this, SLOT(setHexa()));
}
1

There are 1 answers

0
jonspaceharper On BEST ANSWER

Call QLayout::setContentsMargins() for both mainLayout and hbox. Try (3, 3, 3, 3) as parameters for a starting point and tweak. Layouts have default margins of 11 pixels on most platforms, according to the docs.