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

爷,独闯天下 提交于 2019-12-24 14:52:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!