2016-02-20 39 views
0

我正在嘗試製作自定義小部件:用於顯示處理器寄存器,其中包含一個名稱,一個值並且可以以八進制/十進制六進制顯示。代碼顯示在底部。我收到更好的結果時,我使用的代碼,如圖(即我插入QRadioButtons):QGroupBox使用我的QT5自定義小部件進行大小調整

enter image description here

如果我使用

mainLayout->addWidget(DisplayMode); 

代替(我想這是正確的方法),然後將所得圖片

enter image description here

難道我誤解的東西嗎?哪裏不對?

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

兩個mainLayouthbox呼叫QLayout::setContentsMargins()。嘗試(3, 3, 3, 3)作爲起點和調整的參數。根據文檔,佈局在大多數平臺上的默認邊距爲11像素。

相關問題