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. Error in QMenu style
Qt 6.11 is out! See what's new in the release blog

Error in QMenu style

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 2.5k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    TETTRA
    wrote on last edited by
    #1

    When I start my project, the top line(Menu) doesn't fill out completely, how do I resolve it?
    ! picture

    joeQJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What OS and Window manager are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • T TETTRA

        When I start my project, the top line(Menu) doesn't fill out completely, how do I resolve it?
        ! picture

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by
        #3

        @TETTRA Hi, friend, can you show some code snippets?

        Just do it!

        T 1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #4

          It could be that you are using "Exit" "Close" or "Quit" etc which may be same as menu options given by MAC or Ubuntu. They may not show up. OR You may be creating Actions and not adding to MenuBar. As requested by others already, code snippet will help us to resolve the issue.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          https://www.pthinks.com

          T 1 Reply Last reply
          3
          • SGaistS SGaist

            Hi,

            What OS and Window manager are you using ?

            T Offline
            T Offline
            TETTRA
            wrote on last edited by
            #5

            @SGaist Window

            1 Reply Last reply
            0
            • dheerendraD dheerendra

              It could be that you are using "Exit" "Close" or "Quit" etc which may be same as menu options given by MAC or Ubuntu. They may not show up. OR You may be creating Actions and not adding to MenuBar. As requested by others already, code snippet will help us to resolve the issue.

              T Offline
              T Offline
              TETTRA
              wrote on last edited by
              #6

              @dheerendra
              Source:

                  menuBar()->setStyleSheet(StyleHelper::getQMenuStyleSheet());
              
                  //file
                   QMenu *file = menuBar()->addMenu(tr("File"));
                    file->setStyleSheet(StyleHelper::getMenuBarStyleSheet());
              
                     //new
                      QAction *newFile = new QAction (tr("New"),this);
                        newFile->setShortcut(QKeySequence::New);
                        connect(newFile,SIGNAL(triggered()),this,SLOT(newfile()));
                        file->addAction(newFile);
              
                     //open
                      QAction *openFile = new QAction (tr("Open"),this);
                        openFile->setShortcut(QKeySequence::Open);
                        connect(openFile,SIGNAL(triggered()),this,SLOT(open()));
                        file->addAction(openFile);
              
                     //the last document
                       QAction *lastFile = new QAction (tr("The last document"),this);
              
                          file->addAction(lastFile);
                           file->addSeparator();
              
                     //save
                       QAction *saveFile = new QAction (tr("Save"),this);
                          saveFile->setShortcut(QKeySequence::Save);
              
                          file->addAction(saveFile);
              
                     //save as
                       QAction *saveAsFile = new QAction (tr("Save as"),this);
                          saveAsFile->setShortcut(QKeySequence::SaveAs);
                          connect(saveAsFile,SIGNAL(triggered()),this,SLOT(saveAs()));
                          file->addAction(saveAsFile);
                           file->addSeparator();
              
                     //place
                       QAction *placeFile = new QAction (tr("Place"),this);
              
                           file->addAction(placeFile);
                            file->addSeparator();
              
                     //print
                       QAction *printFile = new QAction (tr("Print"),this);
                           printFile->setShortcut(Qt::CTRL+Qt::Key_P);
                           connect(printFile,SIGNAL(triggered()),this,SLOT(printf()));
                            file->addAction(printFile);
                             file->addSeparator();
              
                     //exit
                       QAction *exitFile = new QAction (tr("Exit"),this);
                           exitFile->setShortcut(Qt::CTRL+Qt::Key_Q);
                           connect(exitFile,SIGNAL(triggered()),this,SLOT(close()));
                           file->addAction(exitFile);
              
              
              
                  //edit
              
                    QMenu *edit = menuBar()->addMenu(tr("&Edit"));
                    edit->setStyleSheet(StyleHelper::getMenuBarStyleSheet());
              
                     //cancel
                       QAction *cancelFile = new QAction (tr("Cancel"),this);
                           cancelFile->setShortcut(Qt::CTRL+Qt::Key_Z);
                           edit->addAction(cancelFile);
              
                    //undo
                       QAction *undoFile = new QAction (tr("Undo"),this);
                           undoFile->setShortcut(Qt::ALT+Qt::CTRL+Qt::Key_Z);
                           edit->addAction(undoFile);
                           edit->addSeparator();
              
                    //cut
                       QAction *cutFile = new QAction (tr("Cut"),this);
                           cutFile->setShortcut(Qt::CTRL+Qt::Key_X);
                           edit->addAction(cutFile);
              
                    //copy
                       QAction *copyFile = new QAction (tr("Copy"),this);
                            copyFile->setShortcut(Qt::CTRL+Qt::Key_C);
                            edit->addAction(copyFile);
              
                    //insert
                       QAction *insertFile = new QAction (tr("Insert"),this);
                             insertFile->setShortcut(Qt::CTRL+Qt::Key_V);
                             edit->addAction(insertFile);
              
                    //clear
                       QAction *clearFile = new QAction (tr("Clear"),this);
              
                              edit->addAction(clearFile);
                              edit->addSeparator();
              
              
              
                  //window
              
                     QMenu *window = menuBar()->addMenu(tr("&Window"));
                     window->setStyleSheet(StyleHelper::getMenuBarStyleSheet());
              
                     //full screen mode
                       QAction *fsm = new QAction (tr("Full screen mode"),this);
                           fsm->setShortcut(Qt::Key_F5);
                           connect(fsm,SIGNAL(triggered()),this,SLOT(f_fsm()));
                           window->addAction(fsm);
              
              
                  //reference
              
                     QMenu *reference = menuBar()->addMenu(tr("&Reference"));
                     reference->setStyleSheet(StyleHelper::getMenuBarStyleSheet());
              
                    //About the program "Project"
                       QAction *atp = new QAction (tr("About the program Project"),this);
                           connect(atp,SIGNAL(triggered()),this,SLOT(about()));
                           reference->addAction(atp);
              

              Style:

              QString StyleHelper::getQMenuStyleSheet()
              {
                  return "QMenuBar {"
                         "background-color: #000000;"
                         "color: #FFFFFF;"
                         "}"
                         "QMenuBar::item:selected {"
                         "background-color: #6B6B6B"
                         "}";
              }
              
              
              QString StyleHelper::getMenuBarStyleSheet()
              {
                  return "QMenu { "
                         "background-color: #373737; "
                         "border: #000000;"
                         "color:#FFFFFF;"
                         "}"
                         "QMenu::item:selected {"
                         "background-color: #6E6E6E"
                         "}";
              }
              
              1 Reply Last reply
              0
              • joeQJ joeQ

                @TETTRA Hi, friend, can you show some code snippets?

                T Offline
                T Offline
                TETTRA
                wrote on last edited by
                #7

                @joeQ Part of the code below

                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