Error in QMenu style



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


  • Lifetime Qt Champion

    Hi,

    What OS and Window manager are you using ?



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



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



  • @SGaist Window



  • @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"
               "}";
    }
    


  • @joeQ Part of the code below


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.