minimal example that only depends on Core API

This commit is contained in:
Altair Wei 2021-09-19 22:24:00 +08:00
parent 678f903f5c
commit 93ac6f6ee3
8 changed files with 128 additions and 4 deletions

View File

@ -4,6 +4,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets)
if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
add_subdirectory(widget)
add_subdirectory(mainwindow)
add_subdirectory(minimal)
endif()
if(TARGET Qt${QT_VERSION_MAJOR}::Quick)

View File

@ -0,0 +1,39 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
set(SOURCES
../images.qrc
main.cpp
flwindow.h
flwindow.cpp
)
if(WIN32)
enable_language(RC)
list(APPEND SOURCES ../example.rc ../example.manifest)
endif()
add_executable(minimal WIN32 ${SOURCES})
target_link_libraries(minimal PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
wangwenx190::FramelessHelper
)
target_compile_definitions(minimal PRIVATE
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_KEYWORDS
QT_DEPRECATED_WARNINGS
QT_DISABLE_DEPRECATED_BEFORE=0x060100
)
if(WIN32)
target_link_libraries(minimal PRIVATE dwmapi)
endif()

View File

@ -0,0 +1,38 @@
#include "flwindow.h"
#include "../../framelesshelper.h"
FRAMELESSHELPER_USE_NAMESPACE
FLWindow::FLWindow(QWidget *parent) : QWidget(parent)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
setStyleSheet(QString::fromLatin1("background:blue"));
setAttribute(Qt::WA_ShowModal);
resize(500, 500);
}
FLWindow::~FLWindow()
{
}
void FLWindow::initFramelessWindow()
{
FramelessHelper* helper = new FramelessHelper(windowHandle());
helper->setResizeBorderThickness(8);
helper->setTitleBarHeight(20);
helper->setResizable(true);
helper->install();
}
void FLWindow::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
static bool inited = false;
if (!inited) {
inited = true;
initFramelessWindow();
}
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <QWidget>
class FLWindow : public QWidget
{
Q_OBJECT
public:
explicit FLWindow(QWidget *parent = nullptr);
~FLWindow();
protected:
void showEvent(QShowEvent *event) override;
private:
void initFramelessWindow();
};

21
examples/minimal/main.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <QtWidgets/qapplication.h>
#include "flwindow.h"
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);
FLWindow win;
win.show();
return QApplication::exec();
}

View File

@ -222,8 +222,11 @@ void FramelessHelper::unsetCursor()
void FramelessHelper::updateCursor()
{
if (isHoverResizeHandler())
if (isHoverResizeHandler()) {
setCursor(cursorForFrameSection(m_hoveredFrameSection));
} else {
unsetCursor();
}
}
void FramelessHelper::updateMouse(const QPoint& pos)
@ -239,6 +242,8 @@ void FramelessHelper::updateHoverStates(const QPoint& pos)
bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
{
bool filterOut = false;
if (object == m_window) {
switch (event->type())
{
@ -266,6 +271,8 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
break;
}
}
return filterOut;
}
FRAMELESSHELPER_END_NAMESPACE

View File

@ -29,6 +29,7 @@
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
#include <QtCore/qobject.h>
#include <QtCore/qsize.h>
QT_BEGIN_NAMESPACE
QT_FORWARD_DECLARE_CLASS(QWindow)

View File

@ -38,7 +38,7 @@
FRAMELESSHELPER_BEGIN_NAMESPACE
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
Q_GLOBAL_STATIC(FramelessHelper, framelessHelperUnix)
//Q_GLOBAL_STATIC(FramelessHelper, framelessHelperUnix)
#endif
void FramelessWindowsManager::addWindow(QWindow *window)
@ -51,7 +51,7 @@ void FramelessWindowsManager::addWindow(QWindow *window)
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
}
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
framelessHelperUnix()->removeWindowFrame(window);
//framelessHelperUnix()->removeWindowFrame(window);
#else
FramelessHelperWin::addFramelessWindow(window);
// Work-around a Win32 multi-monitor bug.
@ -165,7 +165,7 @@ void FramelessWindowsManager::removeWindow(QWindow *window)
return;
}
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
framelessHelperUnix()->bringBackWindowFrame(window);
//framelessHelperUnix()->bringBackWindowFrame(window);
#else
FramelessHelperWin::removeFramelessWindow(window);
#endif