#include#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *widget = new QWidget(); widget->setContentsMargins(10, 10, 10, 10); QPushButton *button = new QPushButton("Button", widget); button->setGeometry(50, 50, 100, 30); widget->show(); return app.exec(); }
#includeIn this example, we create a new QWidget and a QVBoxLayout to contain the label. We then set the content margins of the layout to be 20 pixels in all directions. When the widget is displayed, we can see that there is a 20 pixel margin around the label. Package library: Qt#include int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *widget = new QWidget(); QVBoxLayout *layout = new QVBoxLayout(widget); layout->setContentsMargins(20, 20, 20, 20); QLabel *label = new QLabel("This is a label", widget); layout->addWidget(label); widget->show(); return app.exec(); }