The article mainly refers to the one go, two three li big blog https://blog.csdn.net/liang19890820/article/details/50557240 , some modifications and upgrades have been made.
if you need to make a more beautiful form interface, it is very necessary to implement the frameless widget. In this paper, some common controls such as frameless widget, Dialog, MessageBox, etc. are implemented, and some beautification is carried out. You can drag, zoom, double-click the title bar to maximize the restore and other operations. In addition, you can realize the Aero effect under windwindows and package it into a library, so it will be very convenient to use in every project.
First, look at the following renderings:
usage method:
1,FramelessWindow:
#include "framelesswindow.h"
#include <QWidget>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FramelessWindow *pWindow = new FramelessWindow();
QWidget *pCentralWidget = new QWidget(pWindow);
pWindow->setCentralWidget(pCentralWidget);
pWindow->show();
return a.exec();
}
2,FramlessDialog
...
FramelessDialog *pDialog = new FramelessDialog(pWindow);
QWidget *pDlgCentralWidget = new QWidget(pDialog);
QPushButton *pButton = new QPushButton(pDlgCentralWidget);
pDialog->setCentralWidget(pDlgCentralWidget);
pDialog->setModal(true);
pDialog->show();
...
3,FrameMessageBox
FramelessMessageBox::showInformation(pWindow, QObject::tr("Tips!"), QObject::tr("Custom prompt box!"));
Each color can be modified in the qss file.
/**
* Customize borderless forms, dialog boxes and prompt boxes and encapsulate them into libraries / test programs
*
* style.qss
* qss Global files, setting the color theme of the interface, etc.
*
* FlyWM_
* GitHub: https://github.com/FlyWM
* CSDN: https://blog.csdn.net/a844651990
*
*/
/********** Borderless main form**********/
FramelessWindow#framelessWindow {
background-color: #323232;
}
/********************************/
/*********** Title Block**************/
QPushButton#minimizeButton {
border: none;
image: url(:/images/minimizeBtnWhite_16.png);
}
QPushButton#minimizeButton:hover {
background: #505050;
}
QPushButton#maximizeButton {
border: none;
image: url(:/images/restoreWhite_16.png);
}
QPushButton#maximizeButton:hover {
background: #505050;
}
QPushButton#maximizeButton[maximizeProperty=restore] {
image: url(:/images/restoreWhite_16.png);
}
QPushButton#maximizeButton[maximizeProperty=maximize] {
image: url(:/images/maximizeBtnWhite_16.png);
}
QPushButton#closeButton {
border: none;
image: url(:/images/closeBtnWhite_16.png);
}
QPushButton#closeButton:hover {
background: #505050;
}
QPushButton#minimizeButton:pressed {
background: #C8C8C8;
image: url(:/images/minimizeBtnBlack_16.png);
}
QPushButton#maximizeButton:pressed {
background: #C8C8C8;
image: url(:/images/restoreBlack_16.png);
}
QPushButton#closeButton:pressed {
background: #C8C8C8;
image: url(:/images/closeBtnBlack_16.png);
}
QLabel#titleLabel {
color: white;
}
/********************************/
/******* Custom borderless prompt box*******/
FramelessMessageBox#framelessMessagBox {
background-color: #404040;
}
QLabel#messageTextLabel {
color: white;
font-family: "Microsoft Yahei";
font-size: 14pt;
}
QPushButton#yesButton {
background-color: red;
}
/********************************/
/******* Custom borderless dialog*******/
FramelessDialog#framelessDialog {
background-color: #2E2E2E;
}
/********************************/
Code download:
github: https://github.com/FlyWM
csdn: https://download.csdn.net/download/a844651990/10589445