Thalia
Thalia

Reputation: 14615

How can I remove spacing around a widget in a layout?

I am trying to insert a very tiny QLabel into a very tiny QFrame.

The QFrame is used as a spacer and I thought it a perfect place to add text.

In code that text would change (in to mm). Because mm is so giant it is clipped...

Yet it seems to me it would fit if I could just get rid of the margins !

enter image description here

So I try:

ui->tinyFrame is created in Designer... it has geometry 0,0,10,10

QLabel* unitLabel  = new QLabel("mm");
unitLabel->setFixedSize(8,8);
unitLabel->setFont(QFont("Arial Narrow", 7));
unitLabel->setMargin(0);
unitLabel->setContentsMargins(0,0,0,0);

QHBoxLayout* unitLayout = new QHBoxLayout();
unitLayout->setSpacing(0);    // I try everything
unitLayout->setMargin(0);
unitLayout->setContentsMargins(0,0,0,0);
ui->tinyFrame->setLayout(unitLayout);
ui->tinyFrame->setContentsMargins(0,0,0,0);
unitLayout->addWidget(unitLabel);

What else can I try to remove the space around my little label ?

Upvotes: 0

Views: 299

Answers (1)

Alexander V
Alexander V

Reputation: 8698

I am trying to insert a very tiny QLabel into a very tiny QFrame. What can I try to remove the space around my little label?

QLabel is derived from QFrame: maybe you can just replace that QFrame with QLabel then? And no nested layout for that frame.

... as long as you tried layout->setSpacing(0) already...

Upvotes: 1

Related Questions