Lion King
Lion King

Reputation: 33813

How to remove this space(margin) from a QWidget form

I have a QWidget form, then I have added QTextEdit on the form, but there is a space(margin) in the top.

I tried to use the following:

QWidget *widget = new QWidget(this);
widget->layout()->setContentsMargins(0,0,0,0);

But unfortunately, it did not do what I want.

How to remove that space(margin) to be like the left, right and down side ?


Full code

QWidget *widget = new QWidget(this);
QTextEdit *TextEdit = new QTextEdit(widget);
QMdiSubWindow *mdiWindows = ui->mdiArea->addSubWindow(widget);
mdiWindows->setGeometry(5, 5, 300, 250);
mdiWindows->setWindowTitle(finfo.baseName());
mdiWindows->setWindowState(Qt::WindowMaximized);
mdiWindows->layout()->addWidget(TextEdit);
mdiWindows->layout()->setContentsMargins(0,0,0,0);
TextEdit->setText(cache);
widget->setMaximumHeight(0);
mdiWindows->show();

Upvotes: 1

Views: 2290

Answers (2)

tinkertime
tinkertime

Reputation: 3042

Try addding a

widget->layout()->setSpacing(0);

Upvotes: 1

j809
j809

Reputation: 1499

Is it the menubar? Try removing it if you don't need it.

Also, try to position the QTextedit properly on central widget by clicking the widget and using arrow keys to make its position exact.

Also, there might be a layout causing this problem. Please check it.

Upvotes: 0

Related Questions