Modern GUI Frameless Window, how to set Close Button inside Menubar Corner Widget without menubar padding affecting close button.
-
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:
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?
setCornerWidget would work, but problem is the "padding 7px" which pushes the buttons down also. -
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 asQMenuBar::item
)QMenuBar::item { padding: 7px; }
As you can see here
-
@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 issetCornerWidget
.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
. -
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 asQMenuBar::item
)QMenuBar::item { padding: 7px; }
As you can see here
-