Modern GUI Frameless Window, how to set Close Button inside Menubar Corner Widget without menubar padding affecting close button.
-
wrote on 21 Mar 2024, 14:18 last edited by StudentScripter
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. -
@Pl45m4 Changed it but still no clue on how this could be done
wrote on 21 Mar 2024, 15:57 last edited by Pl45m4So 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
-
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.wrote on 21 Mar 2024, 14:51 last edited by@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
. -
@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
.wrote on 21 Mar 2024, 15:42 last edited by StudentScripter@Pl45m4 Changed it but still no clue on how this could be done
-
@Pl45m4 Changed it but still no clue on how this could be done
wrote on 21 Mar 2024, 15:57 last edited by Pl45m4So 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
-
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
wrote on 21 Mar 2024, 16:17 last edited by StudentScripter@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/5