简体   繁体   English

在Qt中使用统一菜单栏

[英]Using unity menu bar in Qt

I have a simple Qt MainWindow: 我有一个简单的Qt MainWindow:

// ui/mainwindow.hpp
class MainWindow: public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget* parent = 0);
public slots:
private:
};

// ui/mainwindow.cpp
MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
{
    QMenu* menuFile = menuBar()->addMenu(tr("File"));
    menuFile->addAction(tr("Some"));
}

// Application entry
int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

I'm noticing that with Ubuntu and Unity, the menu bar is not showing on the top of the screen but instead inside the application's window. 我注意到,使用Ubuntu和Unity时,菜单栏不是显示在屏幕顶部,而是显示在应用程序的窗口内部。

How do I make the menu bar show up on the top of the screen? 如何使菜单栏显示在屏幕顶部?

Which version of Qt are you using? 您正在使用哪个版本的Qt?

  • For Qt 4.8, the package appmenu-qt needs to be installed. 对于Qt 4.8,需要安装软件包appmenu-qt
  • For Qt 5.2+, the package appmenu-qt5 needs to be installed and QT_QPA_PLATFORMTHEME=appmenu-qt5` being set in the environment 对于Qt 5.2+,需要安装软件包appmenu-qt5并在环境中设置QT_QPA_PLATFORMTHEME = appmenu-qt5`

This is not really something that you influence on the app developer's side. 这实际上并不会影响应用程序开发人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM