Skip to content

Commit

Permalink
特性: 统一示例风格, 验证 Qt 5.9.6 Bug 修复情况
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujun59761 committed Jun 28, 2018
1 parent 0bb6647 commit a8822e4
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 48 deletions.
11 changes: 1 addition & 10 deletions FramelessHelper.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ QT += qml quick widgets

TARGET = StyledWindow
TEMPLATE = app
CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000

include(FramelessHelper/FramelessHelper.pri)

Expand Down
3 changes: 3 additions & 0 deletions FramelessHelper.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
<file>res/minimize-button1.png</file>
<file>res/background.png</file>
<file>qml/main.qml</file>
<file>qml/CloseButton.qml</file>
<file>qml/MaximizeButton.qml</file>
<file>qml/MinimizeButton.qml</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions FramelessHelper/Kernels/NativeWindowFilter_p.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef NATIVEWINDOWFILTER_P_H
#define NATIVEWINDOWFILTER_P_H

#include <QHash>
#include <QWindow>

#include "NativeWindowFilter.h"
Expand Down
14 changes: 10 additions & 4 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QTimer>
#include <QWindow>
#include <QScreen>
#include <QPainter>

#include "FramelessHelper.h"

MainWindow::MainWindow(QWidget *parent)
: QWidget(parent, Qt::FramelessWindowHint)
, ui(new Ui::MainWindow())
, window(Q_NULLPTR)
{
ui->setupUi(this);

Expand All @@ -20,6 +22,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->maximizeButton, &QPushButton::clicked,
this, &MainWindow::maximizeButtonClicked);
ui->maximizeButton->setIcon(QIcon(QStringLiteral(":/res/maximize-button1.png")));

QTimer::singleShot(100, this, &MainWindow::syncPosition);
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -60,8 +64,10 @@ void MainWindow::maximizeButtonClicked()
}
}

void MainWindow::on_openWindow_clicked()
void MainWindow::syncPosition()
{
if (window)
window->show();
QWindow *window = windowHandle();
QScreen *screen = window->screen();

window->setX(screen->availableGeometry().width() / 2 + 10);
}
7 changes: 3 additions & 4 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ class MainWindow : public QWidget
bool event(QEvent *event) Q_DECL_FINAL;
protected:
void maximizeButtonClicked();
private slots:
void on_openWindow_clicked();
private:
Ui::MainWindow *ui;
public:
MainWindow *window;

private:
void syncPosition();
};

#endif // MAINWINDOW_H
30 changes: 15 additions & 15 deletions MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
image: url(:/res/close-button2.png);
border-style: none;
background-color: #8c0a15;
}

#label {
color: &quot;#fefefe&quot;;
}</string>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -188,23 +192,19 @@
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>271</height>
</size>
<item row="1" column="0" colspan="4">
<widget class="QLabel" name="label">
<property name="font">
<font>
<family>Arial</family>
<pointsize>28</pointsize>
</font>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="openWindow">
<property name="text">
<string>Open Window</string>
<string>Qt Widgets Inside</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# FramelessHelper

Qt based frameless window class, full features.
Qt based frameless window class, full features. Requires: Qt 5.9.6 +

![](window.png)
25 changes: 25 additions & 0 deletions qml/CloseButton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import QtQuick 2.9
import QtQuick.Controls 2.2

Button {
id: control

width: 45
height: 26

ToolTip.visible: hovered && !down
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: qsTr("Close")

contentItem: Item {
Image {
anchors.centerIn: parent
source: control.down || control.hovered ? "qrc:/res/close-button2.png" : "qrc:/res/close-button1.png"
}
}

background: Rectangle {
visible: control.down || control.hovered
color: control.down ? "#8c0a15" : (control.hovered ? "#e81123" : "transparent")
}
}
27 changes: 27 additions & 0 deletions qml/MaximizeButton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import QtQuick 2.9
import QtQuick.Controls 2.2

Button {
id: control

width: 45
height: 26

ToolTip.visible: hovered && !down
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: qsTr("Maximize")

property bool isMaximized: false

contentItem: Item {
Image {
anchors.centerIn: parent
source: isMaximized ? "qrc:/res/maximize-button2.png" : "qrc:/res/maximize-button1.png"
}
}

background: Rectangle {
visible: control.down || control.hovered
color: control.down ? "#80808080" : (control.hovered ? "#80c7c7c7" : "transparent")
}
}
25 changes: 25 additions & 0 deletions qml/MinimizeButton.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import QtQuick 2.9
import QtQuick.Controls 2.2

Button {
id: control

width: 45
height: 26

ToolTip.visible: hovered && !down
ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
ToolTip.text: qsTr("Minimize")

contentItem: Item {
Image {
anchors.centerIn: parent
source: "qrc:/res/minimize-button1.png"
}
}

background: Rectangle {
visible: control.down || control.hovered
color: control.down ? "#80808080" : (control.hovered ? "#80c7c7c7" : "transparent")
}
}
78 changes: 64 additions & 14 deletions qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import QtQuick 2.2
import QtQuick 2.9
import QtQuick.Window 2.2
import QtShark.Window 1.0

Window {
id: window
visible: true
width: 640
height: 480
width: 400
height: 300
title: qsTr("FramelessHelper")

flags: Qt.FramelessWindowHint
flags: Qt.FramelessWindowHint | Qt.WindowTitleHint

FramelessHelper {
id: framelessHelper
Expand All @@ -19,21 +20,70 @@ Window {
}
}

Rectangle {
id: titleBar
Image {
anchors.fill: parent
source: "qrc:/res/background.png"
}

color: "yellow"
border {
width: 2
color: "blue"
Item {
id: titleBar
anchors {
top: parent.top
left: parent.left
right: parent.right
}

height: 26
}

MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
Row {
anchors {
top: titleBar.top
right: titleBar.right
}

MinimizeButton {
onClicked: {
window.showMinimized();
}
}
MaximizeButton {
isMaximized: Window.Maximized === window.visibility
onClicked: {
if (Window.Maximized === window.visibility) {
window.showNormal();
} else {
window.showMaximized();
}
}
}
CloseButton {
onClicked: {
window.close();
}
}
}

Text {
anchors {
top: titleBar.bottom
left: parent.left
right: parent.right
bottom: parent.bottom
}

text: "Qt Quick Inside"
font {
family: "Arial"
pointSize: 28
}
color: "#fefefe"

verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}

Component.onCompleted: {
window.x = Screen.width / 2 - 410;
}
}
Binary file modified window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a8822e4

Please sign in to comment.