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. Modern GUI Frameless Window, how to set Close Button inside Menubar Corner Widget without menubar padding affecting close button.

Modern GUI Frameless Window, how to set Close Button inside Menubar Corner Widget without menubar padding affecting close button.

Scheduled Pinned Locked Moved Solved General and Desktop
qt c++qmenubarframelesswindow
5 Posts 2 Posters 685 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
    StudentScripter
    wrote on 21 Mar 2024, 14:18 last edited by StudentScripter
    #1

    So as many modern guis do it i wanted to remove the titlebar of my qt application. I've done it with frameless window hint. I want it to look like that: e95c8195-5748-4a18-82dc-baa70d3dada6-image.png

    But i just cant figure out to get a close, maximise and minimise button right besides the menubar.

    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        
    {
        ui->setupUi(this);
        
    
        
       setWindowTitle("Xentury's KSP Editor");
       setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    
       SettingsPage = new SettingsDialog();
    
    
    
    
    //-----------------------------------------------------------------------------
    //Erstellt die MenuBar:
    
        QMenuBar *menuBar = new QMenuBar(this);
        menuBar->setFixedHeight(35);
    
    
        // Erstellen Sie die Schaltflächen
        QPushButton *minimizeButton = new QPushButton("-");
        minimizeButton->setFixedSize(30,35);
        QPushButton *maximizeButton = new QPushButton("+");
        maximizeButton->setFixedSize(30,35);
        QPushButton *closeButton = new QPushButton("x");
        closeButton->setFixedSize(30,35);
    
    
        QWidget *CloseAreaContainer = new QWidget();
        CloseAreaContainer->setContentsMargins(0,0,0,0);
        QHBoxLayout *CloseAreaContainerLayout = new QHBoxLayout();
        CloseAreaContainerLayout->setContentsMargins(0,0,0,0);
        CloseAreaContainerLayout->setSpacing(0);
        CloseAreaContainer->setLayout(CloseAreaContainerLayout);
        CloseAreaContainerLayout->addWidget(minimizeButton);
        CloseAreaContainerLayout->addWidget(maximizeButton);
        CloseAreaContainerLayout->addWidget(closeButton);
    
    
    
    
        QMenu *fileMenu = menuBar->addMenu(tr("&File"));
    
        
        setMenuBar(menuBar);
    }
    

    im using as stylesheet for the menubar:

    /*-----QMenuBar-----*/
    QMenuBar
    {
            background-color: qlineargradient(spread:repeat, x1:1, y1:0, x2:1, y2:1, stop:0 rgba(63, 63, 63, 255),stop:0.293269 rgba(61, 61, 61, 255),stop:0.634615 rgba(59, 59, 59, 255),stop:1 rgba(63, 63, 63, 255));
            border: 1px solid #282828;
            padding: 7px;
            color: #FAF9F6;
            font-weight: bold;
    
    }
    

    It looks like this on my side how do i get the buttons there? 5d45b72c-eec2-448c-9b2f-9c9074213854-image.png
    setCornerWidget would work, but problem is the "padding 7px" which pushes the buttons down also.

    P 1 Reply Last reply 21 Mar 2024, 14:51
    0
    • S StudentScripter
      21 Mar 2024, 15:42

      @Pl45m4 Changed it but still no clue on how this could be done

      P Offline
      P Offline
      Pl45m4
      wrote on 21 Mar 2024, 15:57 last edited by Pl45m4
      #4

      @StudentScripter

      So basically you want padding on your menu buttons but not on the cornerWidget?

      What if you set the padding for the items only?
      (Not sure if the cornerWidget counts as QMenuBar::item)

      QMenuBar::item
      {
           padding: 7px;
      }
      

      As you can see here

      • https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qmenubar

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply 21 Mar 2024, 16:17
      2
      • S StudentScripter
        21 Mar 2024, 14:18

        So as many modern guis do it i wanted to remove the titlebar of my qt application. I've done it with frameless window hint. I want it to look like that: e95c8195-5748-4a18-82dc-baa70d3dada6-image.png

        But i just cant figure out to get a close, maximise and minimise button right besides the menubar.

        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
            
        {
            ui->setupUi(this);
            
        
            
           setWindowTitle("Xentury's KSP Editor");
           setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
        
           SettingsPage = new SettingsDialog();
        
        
        
        
        //-----------------------------------------------------------------------------
        //Erstellt die MenuBar:
        
            QMenuBar *menuBar = new QMenuBar(this);
            menuBar->setFixedHeight(35);
        
        
            // Erstellen Sie die Schaltflächen
            QPushButton *minimizeButton = new QPushButton("-");
            minimizeButton->setFixedSize(30,35);
            QPushButton *maximizeButton = new QPushButton("+");
            maximizeButton->setFixedSize(30,35);
            QPushButton *closeButton = new QPushButton("x");
            closeButton->setFixedSize(30,35);
        
        
            QWidget *CloseAreaContainer = new QWidget();
            CloseAreaContainer->setContentsMargins(0,0,0,0);
            QHBoxLayout *CloseAreaContainerLayout = new QHBoxLayout();
            CloseAreaContainerLayout->setContentsMargins(0,0,0,0);
            CloseAreaContainerLayout->setSpacing(0);
            CloseAreaContainer->setLayout(CloseAreaContainerLayout);
            CloseAreaContainerLayout->addWidget(minimizeButton);
            CloseAreaContainerLayout->addWidget(maximizeButton);
            CloseAreaContainerLayout->addWidget(closeButton);
        
        
        
        
            QMenu *fileMenu = menuBar->addMenu(tr("&File"));
        
            
            setMenuBar(menuBar);
        }
        

        im using as stylesheet for the menubar:

        /*-----QMenuBar-----*/
        QMenuBar
        {
                background-color: qlineargradient(spread:repeat, x1:1, y1:0, x2:1, y2:1, stop:0 rgba(63, 63, 63, 255),stop:0.293269 rgba(61, 61, 61, 255),stop:0.634615 rgba(59, 59, 59, 255),stop:1 rgba(63, 63, 63, 255));
                border: 1px solid #282828;
                padding: 7px;
                color: #FAF9F6;
                font-weight: bold;
        
        }
        

        It looks like this on my side how do i get the buttons there? 5d45b72c-eec2-448c-9b2f-9c9074213854-image.png
        setCornerWidget would work, but problem is the "padding 7px" which pushes the buttons down also.

        P Offline
        P Offline
        Pl45m4
        wrote on 21 Mar 2024, 14:51 last edited by
        #2

        @StudentScripter said in Modern GUI Frameless Window, how to set close button inside QMenuBar?:

        setCornerWidget would work, but problem is the "padding 7px" which pushes the buttons down also.

        Your question and topic title is misleading :)
        As the solution is setCornerWidget.

        • https://doc.qt.io/qt-6/qmenubar.html#setCornerWidget

        This would work and look good if you did not set the padding. So your question should be how to keep the padding of the buttons/actions while not affecting the cornerWidget.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        S 1 Reply Last reply 21 Mar 2024, 15:42
        1
        • P Pl45m4
          21 Mar 2024, 14:51

          @StudentScripter said in Modern GUI Frameless Window, how to set close button inside QMenuBar?:

          setCornerWidget would work, but problem is the "padding 7px" which pushes the buttons down also.

          Your question and topic title is misleading :)
          As the solution is setCornerWidget.

          • https://doc.qt.io/qt-6/qmenubar.html#setCornerWidget

          This would work and look good if you did not set the padding. So your question should be how to keep the padding of the buttons/actions while not affecting the cornerWidget.

          S Offline
          S Offline
          StudentScripter
          wrote on 21 Mar 2024, 15:42 last edited by StudentScripter
          #3

          @Pl45m4 Changed it but still no clue on how this could be done

          P 1 Reply Last reply 21 Mar 2024, 15:57
          0
          • S StudentScripter
            21 Mar 2024, 15:42

            @Pl45m4 Changed it but still no clue on how this could be done

            P Offline
            P Offline
            Pl45m4
            wrote on 21 Mar 2024, 15:57 last edited by Pl45m4
            #4

            @StudentScripter

            So basically you want padding on your menu buttons but not on the cornerWidget?

            What if you set the padding for the items only?
            (Not sure if the cornerWidget counts as QMenuBar::item)

            QMenuBar::item
            {
                 padding: 7px;
            }
            

            As you can see here

            • https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qmenubar

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            S 1 Reply Last reply 21 Mar 2024, 16:17
            2
            • P Pl45m4
              21 Mar 2024, 15:57

              @StudentScripter

              So basically you want padding on your menu buttons but not on the cornerWidget?

              What if you set the padding for the items only?
              (Not sure if the cornerWidget counts as QMenuBar::item)

              QMenuBar::item
              {
                   padding: 7px;
              }
              

              As you can see here

              • https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qmenubar
              S Offline
              S Offline
              StudentScripter
              wrote on 21 Mar 2024, 16:17 last edited by StudentScripter
              #5

              @Pl45m4 Well thank you very much that does the job! Is there any way to make these menu items background heigher without changing the font size.

              EDIT:
              QMenuBar{
              min-height: 20px;
              }

              1 Reply Last reply
              0
              • S StudentScripter has marked this topic as solved on 21 Mar 2024, 16:17

              5/5

              21 Mar 2024, 16:17

              • Login

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