Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. stylesheet is not applying in sub-menu
Forum Update on Monday, May 27th 2025

stylesheet is not applying in sub-menu

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saber
    wrote on last edited by
    #1

    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;
    }
    
    raven-worxR 1 Reply Last reply
    0
    • S saber

      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;
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      S 1 Reply Last reply
      1
      • raven-worxR raven-worx

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

        S Offline
        S Offline
        saber
        wrote on last edited by
        #3

        @raven-worx

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

        AbrarA raven-worxR 2 Replies Last reply
        0
        • S saber

          @raven-worx

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

          AbrarA Offline
          AbrarA Offline
          Abrar
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • S saber

            @raven-worx

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

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

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

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved