Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

stylesheet is not applying in sub-menu



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

    0_1532430402830_Screenshot_2018-07-24_17-04-14.png

    
    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
        openMenu->addAction(ui->actionCoreImage);
        openMenu->addAction(ui->actionCorePaint);
        openMenu->addAction(ui->actionCorePad);
        openMenu->addAction(ui->actionCorePlayer);
        openMenu->addAction(ui->actionCorePDF);
    
        // 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()) {
            continue;
          }
    
          // Load desktop file for application
          DesktopFile df = DesktopFile("/usr/share/applications/" + appName);
    
          // Create action
          QAction* action = new QAction(df.getName(), openMenu);
          action->setData(df.getExec());
          action->setIcon(FileUtils::searchAppIcon(df));
          defaultApps.append(action);
    
          // TODO: icon and connect
          connect(action, SIGNAL(triggered()), SLOT(openInApp()));
    
          // Add action to menu
          openMenu->addAction(action);
        }
    
        // Add open action to menu
        openMenu->addSeparator();
        openMenu->addAction(selectAppAct);
        return openMenu;
    }
    

  • Moderators

    @saber
    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