Add the QMainWindow example.
And re-arrange the examples. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
|
@ -0,0 +1,106 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>497</width>
|
||||||
|
<height>348</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>MainWindow</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>../windows.ico</normaloff>../windows.ico</iconset>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget"/>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>497</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menuItem_1">
|
||||||
|
<property name="title">
|
||||||
|
<string>Menu 1</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionItem_1"/>
|
||||||
|
<addaction name="actionItem_2"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuItem_2">
|
||||||
|
<property name="title">
|
||||||
|
<string>Menu 2</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuMenu_3">
|
||||||
|
<property name="title">
|
||||||
|
<string>Menu 3</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuItem_1"/>
|
||||||
|
<addaction name="menuItem_2"/>
|
||||||
|
<addaction name="menuMenu_3"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<widget class="QDockWidget" name="dockWidget">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dock 1</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="dockWidgetArea">
|
||||||
|
<number>1</number>
|
||||||
|
</attribute>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QDockWidget" name="dockWidget_2">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dock 2</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="dockWidgetArea">
|
||||||
|
<number>1</number>
|
||||||
|
</attribute>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents_2"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="toolBar">
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>toolBar</string>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actionAction_1"/>
|
||||||
|
<addaction name="actionAction_2"/>
|
||||||
|
</widget>
|
||||||
|
<action name="actionAction_1">
|
||||||
|
<property name="text">
|
||||||
|
<string>Action 1</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionAction_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Action 2</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionItem_1">
|
||||||
|
<property name="text">
|
||||||
|
<string>Item 1</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionItem_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Item 2</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -0,0 +1,6 @@
|
||||||
|
TARGET = QMainWindow
|
||||||
|
TEMPLATE = app
|
||||||
|
QT += widgets
|
||||||
|
SOURCES += main.cpp
|
||||||
|
FORMS += TitleBar.ui MainWindow.ui
|
||||||
|
include($$PWD/../common.pri)
|
|
@ -0,0 +1,257 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>TitleBar</class>
|
||||||
|
<widget class="QWidget" name="TitleBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>423</width>
|
||||||
|
<height>26</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">#TitleBar {
|
||||||
|
border-top: 1px solid rgb(255, 255, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
#iconButton, #minimizeButton, #maximizeButton, #closeButton {
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#minimizeButton:hover, #maximizeButton:hover {
|
||||||
|
border-style: none;
|
||||||
|
background-color: #80c7c7c7;
|
||||||
|
}
|
||||||
|
|
||||||
|
#minimizeButton:pressed, #maximizeButton:pressed {
|
||||||
|
border-style: none;
|
||||||
|
background-color: #80808080;
|
||||||
|
}
|
||||||
|
|
||||||
|
#closeButton:hover {
|
||||||
|
border-style: none;
|
||||||
|
background-color: #e81123;
|
||||||
|
}
|
||||||
|
|
||||||
|
#closeButton:pressed {
|
||||||
|
border-style: none;
|
||||||
|
background-color: #8c0a15;
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="iconButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>26</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>26</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>24</width>
|
||||||
|
<height>24</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="titleLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>262</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="minimizeButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::NoContextMenu</enum>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Minimize</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../windows.qrc">
|
||||||
|
<normaloff>:/images/button_minimize_black.svg</normaloff>:/images/button_minimize_black.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>30</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="maximizeButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::NoContextMenu</enum>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Maximize</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../windows.qrc">
|
||||||
|
<normaloff>:/images/button_maximize_black.svg</normaloff>
|
||||||
|
<normalon>:/images/button_restore_black.svg</normalon>:/images/button_maximize_black.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>30</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="closeButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>26</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::NoContextMenu</enum>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../windows.qrc">
|
||||||
|
<normaloff>:/images/button_close_black.svg</normaloff>:/images/button_close_black.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>45</width>
|
||||||
|
<height>30</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<resources>
|
||||||
|
<include location="../windows.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
|
@ -0,0 +1,126 @@
|
||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ui_MainWindow.h"
|
||||||
|
#include "ui_TitleBar.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QWidget>
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
#include "../../winnativeeventfilter.h"
|
||||||
|
#else
|
||||||
|
#include "../../framelesshelper.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
|
||||||
|
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QApplication application(argc, argv);
|
||||||
|
|
||||||
|
#ifndef Q_OS_WINDOWS
|
||||||
|
FramelessHelper helper;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QMainWindow *mainWindow = new QMainWindow;
|
||||||
|
Ui::MainWindow appMainWindow;
|
||||||
|
appMainWindow.setupUi(mainWindow);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
Ui::TitleBar titleBarWidget;
|
||||||
|
titleBarWidget.setupUi(widget);
|
||||||
|
|
||||||
|
QMenuBar *menuBar = mainWindow->menuBar();
|
||||||
|
titleBarWidget.horizontalLayout->insertWidget(1, menuBar);
|
||||||
|
menuBar->setMaximumHeight(20);
|
||||||
|
|
||||||
|
titleBarWidget.iconButton->setIcon(mainWindow->windowIcon());
|
||||||
|
titleBarWidget.titleLabel->setText(mainWindow->windowTitle());
|
||||||
|
|
||||||
|
mainWindow->setMenuWidget(widget);
|
||||||
|
|
||||||
|
QObject::connect(mainWindow,
|
||||||
|
&QMainWindow::windowIconChanged,
|
||||||
|
titleBarWidget.iconButton,
|
||||||
|
&QPushButton::setIcon);
|
||||||
|
QObject::connect(mainWindow,
|
||||||
|
&QMainWindow::windowTitleChanged,
|
||||||
|
titleBarWidget.titleLabel,
|
||||||
|
&QLabel::setText);
|
||||||
|
QObject::connect(titleBarWidget.closeButton,
|
||||||
|
&QPushButton::clicked,
|
||||||
|
mainWindow,
|
||||||
|
&QMainWindow::close);
|
||||||
|
QObject::connect(titleBarWidget.minimizeButton,
|
||||||
|
&QPushButton::clicked,
|
||||||
|
mainWindow,
|
||||||
|
&QMainWindow::showMinimized);
|
||||||
|
QObject::connect(titleBarWidget.maximizeButton,
|
||||||
|
&QPushButton::clicked,
|
||||||
|
[mainWindow, titleBarWidget]() {
|
||||||
|
if (mainWindow->isMaximized()) {
|
||||||
|
mainWindow->showNormal();
|
||||||
|
titleBarWidget.maximizeButton->setToolTip(QObject::tr("Maximize"));
|
||||||
|
} else {
|
||||||
|
mainWindow->showMaximized();
|
||||||
|
titleBarWidget.maximizeButton->setToolTip(QObject::tr("Restore"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
WinNativeEventFilter::addFramelessWindow(mainWindow);
|
||||||
|
const auto data = WinNativeEventFilter::windowData(mainWindow);
|
||||||
|
if (data) {
|
||||||
|
data->ignoreObjects << titleBarWidget.iconButton << titleBarWidget.minimizeButton
|
||||||
|
<< titleBarWidget.maximizeButton << titleBarWidget.closeButton
|
||||||
|
<< appMainWindow.menubar;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
helper.setIgnoreObjects(mainWindow,
|
||||||
|
{titleBarWidget.iconButton,
|
||||||
|
titleBarWidget.minimizeButton,
|
||||||
|
titleBarWidget.maximizeButton,
|
||||||
|
titleBarWidget.closeButton,
|
||||||
|
appMainWindow.menubar});
|
||||||
|
helper.removeWindowFrame(mainWindow);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mainWindow->resize(800, 600);
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
WinNativeEventFilter::moveWindowToDesktopCenter(mainWindow);
|
||||||
|
#else
|
||||||
|
FramelessHelper::moveWindowToDesktopCenter(mainWindow);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mainWindow->show();
|
||||||
|
|
||||||
|
return QApplication::exec();
|
||||||
|
}
|
Before Width: | Height: | Size: 133 KiB After Width: | Height: | Size: 133 KiB |
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 130 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
@ -0,0 +1,5 @@
|
||||||
|
TARGET = QWidget
|
||||||
|
TEMPLATE = app
|
||||||
|
QT += widgets
|
||||||
|
SOURCES += main.cpp
|
||||||
|
include($$PWD/../common.pri)
|
|
@ -22,37 +22,40 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "winnativeeventfilter.h"
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QOperatingSystemVersion>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#ifdef QT_QUICK_LIB
|
#ifdef Q_OS_WINDOWS
|
||||||
#include "framelessquickhelper.h"
|
#include "../../winnativeeventfilter.h"
|
||||||
#include <QQmlApplicationEngine>
|
#include <QOperatingSystemVersion>
|
||||||
#include <QQmlProperty>
|
#include <QPainter>
|
||||||
|
#else
|
||||||
|
#include "../../framelesshelper.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline bool shouldHaveWindowFrame()
|
static inline bool shouldHaveWindowFrame()
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
|
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
class FramelessWidget : public QWidget
|
class Widget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DISABLE_COPY_MOVE(FramelessWidget)
|
Q_DISABLE_COPY_MOVE(Widget)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FramelessWidget(QWidget *parent = nullptr) : QWidget(parent)
|
explicit Widget(QWidget *parent = nullptr) : QWidget(parent)
|
||||||
{
|
{
|
||||||
isWin10OrGreater = shouldHaveWindowFrame();
|
isWin10OrGreater = shouldHaveWindowFrame();
|
||||||
}
|
}
|
||||||
~FramelessWidget() override = default;
|
~Widget() override = default;
|
||||||
|
|
||||||
bool isNormaled() const { return !isMinimized() && !isMaximized() && !isFullScreen(); }
|
bool isNormaled() const { return !isMinimized() && !isMaximized() && !isFullScreen(); }
|
||||||
|
|
||||||
|
@ -60,6 +63,7 @@ protected:
|
||||||
void paintEvent(QPaintEvent *event) override
|
void paintEvent(QPaintEvent *event) override
|
||||||
{
|
{
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
if (isWin10OrGreater && isNormaled()) {
|
if (isWin10OrGreater && isNormaled()) {
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.save();
|
painter.save();
|
||||||
|
@ -70,6 +74,7 @@ protected:
|
||||||
// painter.drawLine(width(), 0, width(), height());
|
// painter.drawLine(width(), 0, width(), height());
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -104,8 +109,11 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QApplication application(argc, argv);
|
QApplication application(argc, argv);
|
||||||
|
|
||||||
// Qt Widgets example:
|
#ifndef Q_OS_WINDOWS
|
||||||
FramelessWidget widget;
|
FramelessHelper helper;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Widget widget;
|
||||||
widget.setContentsMargins(2, 2, 2, 2);
|
widget.setContentsMargins(2, 2, 2, 2);
|
||||||
QLabel *label = new QLabel;
|
QLabel *label = new QLabel;
|
||||||
QObject::connect(&widget, &QWidget::windowTitleChanged, label, &QLabel::setText);
|
QObject::connect(&widget, &QWidget::windowTitleChanged, label, &QLabel::setText);
|
||||||
|
@ -142,44 +150,25 @@ int main(int argc, char *argv[])
|
||||||
mainLayout->addStretch();
|
mainLayout->addStretch();
|
||||||
widget.setLayout(mainLayout);
|
widget.setLayout(mainLayout);
|
||||||
widget.setWindowTitle(QObject::tr("Hello, World!"));
|
widget.setWindowTitle(QObject::tr("Hello, World!"));
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
WinNativeEventFilter::addFramelessWindow(&widget);
|
WinNativeEventFilter::addFramelessWindow(&widget);
|
||||||
const auto data_widget = WinNativeEventFilter::windowData(&widget);
|
const auto data = WinNativeEventFilter::windowData(&widget);
|
||||||
if (data_widget) {
|
if (data) {
|
||||||
data_widget->ignoreObjects << minimizeButton << maximizeButton << closeButton;
|
data->ignoreObjects << minimizeButton << maximizeButton << closeButton;
|
||||||
}
|
}
|
||||||
widget.resize(800, 600);
|
#else
|
||||||
WinNativeEventFilter::moveWindowToDesktopCenter(&widget);
|
helper.setIgnoreObjects(&widget, {minimizeButton, maximizeButton, closeButton});
|
||||||
widget.show();
|
helper.removeWindowFrame(&widget);
|
||||||
|
|
||||||
#ifdef QT_QUICK_LIB
|
|
||||||
// Qt Quick example:
|
|
||||||
QQmlApplicationEngine engine;
|
|
||||||
qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0, "FramelessHelper");
|
|
||||||
const QUrl mainQmlUrl(QString::fromUtf8("qrc:///qml/main.qml"));
|
|
||||||
const QMetaObject::Connection connection = QObject::connect(
|
|
||||||
&engine,
|
|
||||||
&QQmlApplicationEngine::objectCreated,
|
|
||||||
&application,
|
|
||||||
[&mainQmlUrl, &connection](QObject *object, const QUrl &url) {
|
|
||||||
if (url != mainQmlUrl) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!object) {
|
|
||||||
QGuiApplication::exit(-1);
|
|
||||||
} else {
|
|
||||||
QObject::disconnect(connection);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
engine.load(mainQmlUrl);
|
|
||||||
QList<QObject *> rootObjs = engine.rootObjects();
|
|
||||||
Q_ASSERT(!rootObjs.isEmpty());
|
|
||||||
QObject *rootObj = rootObjs.at(0);
|
|
||||||
Q_ASSERT(rootObj);
|
|
||||||
QQmlProperty::write(rootObj, QString::fromUtf8("isWin10OrGreater"), shouldHaveWindowFrame());
|
|
||||||
#endif
|
#endif
|
||||||
|
widget.resize(800, 600);
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
WinNativeEventFilter::moveWindowToDesktopCenter(&widget);
|
||||||
|
#else
|
||||||
|
FramelessHelper::moveWindowToDesktopCenter(&widget);
|
||||||
|
#endif
|
||||||
|
widget.show();
|
||||||
|
|
||||||
return QApplication::exec();
|
return QApplication::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "main_windows.moc"
|
#include "main.moc"
|
|
@ -0,0 +1,6 @@
|
||||||
|
TARGET = Quick
|
||||||
|
TEMPLATE = app
|
||||||
|
QT += quick
|
||||||
|
HEADERS += $$PWD/../../framelessquickhelper.h
|
||||||
|
SOURCES += $$PWD/../../framelessquickhelper.cpp main.cpp
|
||||||
|
include($$PWD/../common.pri)
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../framelessquickhelper.h"
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QQmlProperty>
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
#include <QOperatingSystemVersion>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline bool shouldHaveWindowFrame()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||||
|
// High DPI scaling is enabled by default from Qt 6
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
// Windows: we are using the manifest file to get maximum compatibility
|
||||||
|
// because some APIs are not supprted on old systems such as Windows 7
|
||||||
|
// and Windows 8. And once we have set the DPI awareness level in the
|
||||||
|
// manifest file, any attemptation to try to change it through API will
|
||||||
|
// fail. In other words, Qt won't be able to enable or disable high DPI
|
||||||
|
// scaling or change the DPI awareness level once we have set it in the
|
||||||
|
// manifest file. So the following two lines are uesless actually (However,
|
||||||
|
// they are still useful on other platforms).
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
|
// Don't round the scale factor.
|
||||||
|
// This will break QWidget applications because they can't render correctly.
|
||||||
|
// Qt Quick applications won't have this issue.
|
||||||
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
|
||||||
|
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QGuiApplication application(argc, argv);
|
||||||
|
|
||||||
|
QQmlApplicationEngine engine;
|
||||||
|
qmlRegisterType<FramelessQuickHelper>("wangwenx190.Utils", 1, 0, "FramelessHelper");
|
||||||
|
const QUrl mainQmlUrl(QString::fromUtf8("qrc:///qml/main.qml"));
|
||||||
|
const QMetaObject::Connection connection = QObject::connect(
|
||||||
|
&engine,
|
||||||
|
&QQmlApplicationEngine::objectCreated,
|
||||||
|
&application,
|
||||||
|
[&mainQmlUrl, &connection](QObject *object, const QUrl &url) {
|
||||||
|
if (url != mainQmlUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!object) {
|
||||||
|
QGuiApplication::exit(-1);
|
||||||
|
} else {
|
||||||
|
QObject::disconnect(connection);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
engine.load(mainQmlUrl);
|
||||||
|
QList<QObject *> rootObjs = engine.rootObjects();
|
||||||
|
Q_ASSERT(!rootObjs.isEmpty());
|
||||||
|
QObject *rootObj = rootObjs.at(0);
|
||||||
|
Q_ASSERT(rootObj);
|
||||||
|
QQmlProperty::write(rootObj, QString::fromUtf8("isWin10OrGreater"), shouldHaveWindowFrame());
|
||||||
|
|
||||||
|
return QGuiApplication::exec();
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
QT += gui-private
|
||||||
|
CONFIG += c++17 strict_c++ utf8_source warn_on
|
||||||
|
DEFINES += \
|
||||||
|
QT_NO_CAST_FROM_ASCII \
|
||||||
|
QT_NO_CAST_TO_ASCII \
|
||||||
|
FRAMELESSHELPER_STATIC
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/../framelesshelper_global.h \
|
||||||
|
$$PWD/../framelesshelper.h
|
||||||
|
SOURCES += $$PWD/../framelesshelper.cpp
|
||||||
|
win32 {
|
||||||
|
DEFINES += WIN32_LEAN_AND_MEAN _CRT_SECURE_NO_WARNINGS
|
||||||
|
CONFIG += windeployqt
|
||||||
|
CONFIG -= embed_manifest_exe
|
||||||
|
HEADERS += $$PWD/../winnativeeventfilter.h
|
||||||
|
SOURCES += $$PWD/../winnativeeventfilter.cpp
|
||||||
|
LINK_TO_SYSTEM_DLL {
|
||||||
|
DEFINES += WNEF_LINK_SYSLIB
|
||||||
|
LIBS += -luser32 -lgdi32 -ldwmapi -lshcore -ld2d1
|
||||||
|
}
|
||||||
|
RESOURCES += $$PWD/windows.qrc
|
||||||
|
RC_FILE = $$PWD/windows.rc
|
||||||
|
OTHER_FILES += $$PWD/windows.manifest
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
TEMPLATE = subdirs
|
||||||
|
CONFIG -= ordered
|
||||||
|
qtHaveModule(widgets): SUBDIRS += QWidget QMainWindow
|
||||||
|
qtHaveModule(quick): SUBDIRS += Quick
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
@ -0,0 +1,18 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/qml">
|
||||||
|
<file alias="main.qml">../resources/qml/main.qml</file>
|
||||||
|
<file alias="MinimizeButton.qml">../resources/qml/MinimizeButton.qml</file>
|
||||||
|
<file alias="MaximizeButton.qml">../resources/qml/MaximizeButton.qml</file>
|
||||||
|
<file alias="CloseButton.qml">../resources/qml/CloseButton.qml</file>
|
||||||
|
</qresource>
|
||||||
|
<qresource prefix="/images">
|
||||||
|
<file alias="button_minimize_black.svg">../resources/images/button_minimize_black.svg</file>
|
||||||
|
<file alias="button_minimize_white.svg">../resources/images/button_minimize_white.svg</file>
|
||||||
|
<file alias="button_maximize_black.svg">../resources/images/button_maximize_black.svg</file>
|
||||||
|
<file alias="button_maximize_white.svg">../resources/images/button_maximize_white.svg</file>
|
||||||
|
<file alias="button_restore_black.svg">../resources/images/button_restore_black.svg</file>
|
||||||
|
<file alias="button_restore_white.svg">../resources/images/button_restore_white.svg</file>
|
||||||
|
<file alias="button_close_black.svg">../resources/images/button_close_black.svg</file>
|
||||||
|
<file alias="button_close_white.svg">../resources/images/button_close_white.svg</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
|
@ -24,9 +24,9 @@
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
IDI_ICON1 ICON "framelesshelper_windows.ico"
|
IDI_ICON1 ICON "windows.ico"
|
||||||
|
|
||||||
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "framelesshelper_windows.manifest"
|
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "windows.manifest"
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,0,0,0
|
FILEVERSION 1,0,0,0
|
||||||
|
@ -47,15 +47,11 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "Comments", "Built by the Qt Toolkit."
|
VALUE "Comments", "Built by the Qt Toolkit."
|
||||||
VALUE "CompanyName", "wangwenx190"
|
VALUE "CompanyName", "wangwenx190"
|
||||||
VALUE "FileDescription", "A framelesshelper based Qt application."
|
VALUE "FileDescription", "A FramelessHelper based Qt application."
|
||||||
VALUE "FileVersion", "1.0.0.0"
|
VALUE "FileVersion", "1.0.0.0"
|
||||||
VALUE "InternalName", "flh-test-app"
|
VALUE "InternalName", ""
|
||||||
VALUE "LegalCopyright", "MIT License"
|
VALUE "LegalCopyright", "MIT License"
|
||||||
#ifdef _DEBUG
|
VALUE "OriginalFilename", ""
|
||||||
VALUE "OriginalFilename", "framelessapplicationd.exe"
|
|
||||||
#else
|
|
||||||
VALUE "OriginalFilename", "framelessapplication.exe"
|
|
||||||
#endif
|
|
||||||
VALUE "ProductName", "Test Application"
|
VALUE "ProductName", "Test Application"
|
||||||
VALUE "ProductVersion", "1.0.0.0"
|
VALUE "ProductVersion", "1.0.0.0"
|
||||||
END
|
END
|
|
@ -1,18 +0,0 @@
|
||||||
TARGET = framelessapplication
|
|
||||||
CONFIG(debug, debug|release): TARGET = $$join(TARGET,,,_debug)
|
|
||||||
TEMPLATE = app
|
|
||||||
QT += gui-private
|
|
||||||
qtHaveModule(widgets): QT += widgets
|
|
||||||
qtHaveModule(quick) {
|
|
||||||
QT += quick
|
|
||||||
HEADERS += framelessquickhelper.h
|
|
||||||
SOURCES += framelessquickhelper.cpp
|
|
||||||
}
|
|
||||||
CONFIG += c++17 strict_c++ warn_on utf8_source
|
|
||||||
DEFINES += \
|
|
||||||
QT_NO_CAST_FROM_ASCII \
|
|
||||||
QT_NO_CAST_TO_ASCII \
|
|
||||||
FRAMELESSHELPER_STATIC
|
|
||||||
VERSION = 1.0.0
|
|
||||||
HEADERS += framelesshelper_global.h framelesshelper.h
|
|
||||||
SOURCES += framelesshelper.cpp main_unix.cpp
|
|
|
@ -1,27 +0,0 @@
|
||||||
TARGET = framelessapplication
|
|
||||||
CONFIG(debug, debug|release): TARGET = $$join(TARGET,,,d)
|
|
||||||
TEMPLATE = app
|
|
||||||
QT += gui-private
|
|
||||||
qtHaveModule(widgets): QT += widgets
|
|
||||||
qtHaveModule(quick) {
|
|
||||||
QT += quick
|
|
||||||
HEADERS += framelessquickhelper.h
|
|
||||||
SOURCES += framelessquickhelper.cpp
|
|
||||||
}
|
|
||||||
CONFIG += c++17 strict_c++ utf8_source warn_on windeployqt
|
|
||||||
DEFINES += \
|
|
||||||
WIN32_LEAN_AND_MEAN \
|
|
||||||
_CRT_SECURE_NO_WARNINGS \
|
|
||||||
QT_NO_CAST_FROM_ASCII \
|
|
||||||
QT_NO_CAST_TO_ASCII \
|
|
||||||
FRAMELESSHELPER_STATIC
|
|
||||||
LINK_TO_SYSTEM_DLL {
|
|
||||||
DEFINES += WNEF_LINK_SYSLIB
|
|
||||||
LIBS += -luser32 -lgdi32 -ldwmapi -lshcore -ld2d1
|
|
||||||
}
|
|
||||||
CONFIG -= embed_manifest_exe
|
|
||||||
RC_FILE = framelesshelper_windows.rc
|
|
||||||
HEADERS += framelesshelper_global.h winnativeeventfilter.h
|
|
||||||
SOURCES += winnativeeventfilter.cpp main_windows.cpp
|
|
||||||
RESOURCES += framelesshelper_windows.qrc
|
|
||||||
OTHER_FILES += framelesshelper_windows.manifest
|
|
|
@ -1,18 +0,0 @@
|
||||||
<RCC>
|
|
||||||
<qresource prefix="/qml">
|
|
||||||
<file alias="main.qml">resources/qml/main.qml</file>
|
|
||||||
<file alias="MinimizeButton.qml">resources/qml/MinimizeButton.qml</file>
|
|
||||||
<file alias="MaximizeButton.qml">resources/qml/MaximizeButton.qml</file>
|
|
||||||
<file alias="CloseButton.qml">resources/qml/CloseButton.qml</file>
|
|
||||||
</qresource>
|
|
||||||
<qresource prefix="/images">
|
|
||||||
<file alias="button_minimize_black.svg">resources/images/button_minimize_black.svg</file>
|
|
||||||
<file alias="button_minimize_white.svg">resources/images/button_minimize_white.svg</file>
|
|
||||||
<file alias="button_maximize_black.svg">resources/images/button_maximize_black.svg</file>
|
|
||||||
<file alias="button_maximize_white.svg">resources/images/button_maximize_white.svg</file>
|
|
||||||
<file alias="button_restore_black.svg">resources/images/button_restore_black.svg</file>
|
|
||||||
<file alias="button_restore_white.svg">resources/images/button_restore_white.svg</file>
|
|
||||||
<file alias="button_close_black.svg">resources/images/button_close_black.svg</file>
|
|
||||||
<file alias="button_close_white.svg">resources/images/button_close_white.svg</file>
|
|
||||||
</qresource>
|
|
||||||
</RCC>
|
|
|
@ -1,96 +0,0 @@
|
||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 by wangwenx190 (Yuhang Zhao)
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "framelesshelper.h"
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
// High DPI scaling is enabled by default from Qt 6
|
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
||||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
||||||
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
|
||||||
// Don't round the scale factor.
|
|
||||||
// This will break QWidget applications because they can't render correctly.
|
|
||||||
// Qt Quick applications won't have this issue.
|
|
||||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(
|
|
||||||
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QApplication application(argc, argv);
|
|
||||||
|
|
||||||
FramelessHelper helper;
|
|
||||||
|
|
||||||
QWidget widget;
|
|
||||||
widget.setContentsMargins(0, 0, 0, 0);
|
|
||||||
QLabel *label = new QLabel;
|
|
||||||
QObject::connect(&widget, &QWidget::windowTitleChanged, label, &QLabel::setText);
|
|
||||||
QPushButton *minimizeButton = new QPushButton;
|
|
||||||
minimizeButton->setText(QObject::tr("Minimize"));
|
|
||||||
QObject::connect(minimizeButton, &QPushButton::clicked, &widget, &QWidget::showMinimized);
|
|
||||||
QPushButton *maximizeButton = new QPushButton;
|
|
||||||
maximizeButton->setText(QObject::tr("Maximize"));
|
|
||||||
QObject::connect(maximizeButton, &QPushButton::clicked, [&widget, &maximizeButton]() {
|
|
||||||
if (widget.isMaximized()) {
|
|
||||||
widget.showNormal();
|
|
||||||
maximizeButton->setText(QObject::tr("Maximize"));
|
|
||||||
} else {
|
|
||||||
widget.showMaximized();
|
|
||||||
maximizeButton->setText(QObject::tr("Restore"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
QPushButton *closeButton = new QPushButton;
|
|
||||||
closeButton->setText(QObject::tr("Close"));
|
|
||||||
QObject::connect(closeButton, &QPushButton::clicked, &widget, &QWidget::close);
|
|
||||||
QHBoxLayout *tbLayout = new QHBoxLayout;
|
|
||||||
tbLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
tbLayout->setSpacing(0);
|
|
||||||
tbLayout->addSpacing(15);
|
|
||||||
tbLayout->addWidget(label);
|
|
||||||
tbLayout->addStretch();
|
|
||||||
tbLayout->addWidget(minimizeButton);
|
|
||||||
tbLayout->addWidget(maximizeButton);
|
|
||||||
tbLayout->addWidget(closeButton);
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
||||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
mainLayout->setSpacing(0);
|
|
||||||
mainLayout->addLayout(tbLayout);
|
|
||||||
mainLayout->addStretch();
|
|
||||||
widget.setLayout(mainLayout);
|
|
||||||
widget.setWindowTitle(QObject::tr("Hello, World!"));
|
|
||||||
helper.setIgnoreObjects(&widget, {minimizeButton, maximizeButton, closeButton});
|
|
||||||
helper.removeWindowFrame(&widget);
|
|
||||||
widget.resize(800, 600);
|
|
||||||
FramelessHelper::moveWindowToDesktopCenter(&widget);
|
|
||||||
widget.show();
|
|
||||||
|
|
||||||
return QApplication::exec();
|
|
||||||
}
|
|