问题
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();
回答1:
Try addding a
widget->layout()->setSpacing(0);
回答2:
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.
来源:https://stackoverflow.com/questions/24289676/how-to-remove-this-spacemargin-from-a-qwidget-form