Nominate our 2022 Qt Champions!

stylesheet is not applying in sub-menu

  • i applied this stylesheet .it applied fine in menu but sub menu is not showing the stylesheet


    QMenu {
        background-color: @color01;
        color: @color07;
        border: 1px solid @color05;}
    QMenu::item {
        background-color: transparent;}
    QMenu::item:selected {
        background-color: @color04;}
    QMenu::separator {
        height: 1px;
        background: @color05;
        margin-left: 10px;
        margin-right: 5px;}

    the sub-menu is created by another function

    QMenu* corefm::createOpenWithMenu()
        QMenu *openMenu = new QMenu(tr("Open with"));
        // Adding CoreApps
        // Select action
        QAction *selectAppAct = new QAction(tr("Select..."), openMenu);
        connect(selectAppAct, SIGNAL(triggered()), this, SLOT(selectApp()));
        // Load default applications for current mime
        QString mime = mimeUtils->getMimeType(curIndex.filePath());
        QStringList appNames = mimeUtils->getDefault(mime);
        // Create actions for opening
        QList<QAction*> defaultApps;
        foreach (QString appName, appNames) {
          // Skip empty app name
          if (appName.isEmpty()) {
          // Load desktop file for application
          DesktopFile df = DesktopFile("/usr/share/applications/" + appName);
          // Create action
          QAction* action = new QAction(df.getName(), openMenu);
          // TODO: icon and connect
          connect(action, SIGNAL(triggered()), SLOT(openInApp()));
          // Add action to menu
        // Add open action to menu
        return openMenu;

  • Moderators

    if possible, you can try to set the stylesheet globally on the QApplication instance.
    This should affect all windows, even those outside the parent-child hierarchy (or make sure that the created sub-menu has the correct parent menu widget set in order to inherit the style)

  • @raven-worx

    i added the stylesheet globally on the QApplication .but not changes.
    how can i set the submenu parent ??

  • @saber make sure all of the menu you created is under your 'this' class. Means add parent for every QMenu.
    I think it will solve your stylesheet problem.

  • Moderators

    @saber said in stylesheet is not applying in sub-menu:

    i added the stylesheet globally on the QApplication .but not changes.

    how exactly? This approach should definitely work
    Also whats the type of the corefm class?

Log in to reply