我是 qt 的新手并正在探索它。我希望在主窗口的工具栏中有一个居中对齐的文本。下面是我在 MainWindow 构造函数中的代码:
QLabel* label=new QLabel("Hello World");
label->setAlignment(Qt::AlignHCenter);
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(label);
QWidget* wid = new QWidget;
wid->setLayout(layout);
ui->mainToolBar->addWidget(wid);
上面的代码显示文本,但不在中心。它显示在左侧。我错过了什么?任何帮助都会非常有帮助。