简体   繁体   中英

QT File menu not integrating into title bar

I am writing a basic gui application in QT creator 3.5.1 and I am using QT 5.5. I have downloaded QT/QT creator via their website. I am currently running Ubuntu 15.04 64 bit.

I am running into an issue regarding the integration of the menu bar into the title bar. The issue being that no integration is happening (the menu bar isn't appearing in the title bar) . The menu bar appears where it would have in the past, below the tile bar. Here is an image of what is happening:

文件菜单问题

How can I go about resolving this issue?

UPDATE:

I installed qt 5.4.1 via apt-get, and qt creator. When I compile against this, my title bar integration works! So the question is, what is different? The people I am developing with are using QT 5.5.1, and I would like to use the same version as them. Is there something I can do differently this time around?

The unique way that i found was in this blog . He claims that this method works on Qt Creator, but i've tested on Ubuntu 32/64 bits Qt5 apps (developed by me) and it seems to works fine too!

The steps are:

  1. Open terminal
  2. Enter sudo apt-get install libgtk2.0-dev libdbusmenu-qt5-dev
  3. Set current directory with CD command (the appmenu project will live here)
  4. Enter command apt-get source appmenu-qt5

Now, the blog still using command line but the next steps can be done by opening the project in Qt Creator (the project is on the current directory).

  1. Using some text editor (can be Qt Creator of course), edit the following lines of appmenu/src/src.pro :

    CONFIG += X11 link_pkgconfig debug

    PKGCONFIG += dbusmenu-qt5 gtk+-2.0

    DESTDIR = ./

to (if you want a dynamic library):

CONFIG += X11 link_pkgconfig
PKGCONFIG += dbusmenu-qt5 gtk+-2.0

or (if you want a statically linked library):

CONFIG += X11 link_pkgconfig static
PKGCONFIG += dbusmenu-qt5 gtk+-2.0
  1. Open the project with Qt Creator (if you haven't done already) select the mode of build (Release mode seems to be smaller in size) and build.

  2. If built succesfully (as a dynamic library), you will have inside your Qt5 installation folder /plugins/platformthemes a plugin called libappmenu-qt5.so . To get menu integration, just place the lib in a platformthemes subfolder of your target app (including Qt Creator).

Or if built succesfully (as a statically linked library), you will have inside your Qt5 installation folder /plugins/platformthemes a file libappmenu-qt5.a . This is the static library. To integrate it with your app, add to your project file:

QT       +=  core-private gui-private platformsupport-private dbus widgets

LIBS     += $$[QT_INSTALL_DATA]/plugins/platformthemes/libappmenu-qt5.a

CONFIG    += X11 link_pkgconfig
PKGCONFIG += dbusmenu-qt5 gtk+-2.0

And to your main.cpp :

#include <QtPlugin>

Q_IMPORT_PLUGIN(AppMenuPlatformThemePlugin)

int main(int argc, char *argv[])
...

And this should be the result:

Qt创作者

Edit (valid when building as dynamic library) : Note that you wouldn't need to recompile your Qt apps nor Qt Creator .

For Qt Creator you need to place libappmenu-qt5.so in your Qt Installation folder: /Tools/QtCreator/lib/Qt/plugins/platformthemes

If you want to redistribute your Qt application, just share inside the folder of your executable the folder platformthemes with libappmenu-qt5.so inside it. Like any other Qt plugin.

Edit 2: Is also possible to build a statically linked plugin, if you don't want extra dependencies.

You can try to set " nativeMenuBar " property of QMenuBar Object is false . Because this property has the default value is true .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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