Qt 的菜单栏显示出问题,堆在右上角,需要怎么解决呢?
this->mMenuBar = new QMenuBar(this);
QMenu *menuMenu = this->mMenuBar->addMenu("菜单");
QMenu *aboutMenu = this->mMenuBar->addMenu("关于");
// 添加具体的菜单功能
QAction *someAction = menuMenu->addAction("或许有菜单");
connect(someAction, &QAction::triggered, this, &Widget::onSomeActionTriggered);
QAction *aboutToolAction = aboutMenu->addAction("关于软件");
connect(aboutToolAction, &QAction::triggered, this, &Widget::OnAboutToolActionTriggered);
QAction *aboutAuthorAction = aboutMenu->addAction("关于作者");
connect(aboutAuthorAction, &QAction::triggered, this, &Widget::onAboutAuthorActionTriggered);
// 设置菜单栏的高度为固定的19像素
QString styleSheet = QString("QMenuBar { height: %1px; }").arg(19);
this->mMenuBar->setStyleSheet(styleSheet);
// 将菜单放入布局中
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMenuBar(this->mMenuBar);
setLayout(layout);
把布局去掉试试看
【相关推荐】