forked from github_mirror/framelesshelper
minimal example that only depends on Core API
This commit is contained in:
parent
678f903f5c
commit
93ac6f6ee3
|
@ -4,6 +4,7 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets)
|
||||||
if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
if(TARGET Qt${QT_VERSION_MAJOR}::Widgets)
|
||||||
add_subdirectory(widget)
|
add_subdirectory(widget)
|
||||||
add_subdirectory(mainwindow)
|
add_subdirectory(mainwindow)
|
||||||
|
add_subdirectory(minimal)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TARGET Qt${QT_VERSION_MAJOR}::Quick)
|
if(TARGET Qt${QT_VERSION_MAJOR}::Quick)
|
||||||
|
|
|
@ -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()
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
};
|
|
@ -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();
|
||||||
|
}
|
|
@ -222,8 +222,11 @@ void FramelessHelper::unsetCursor()
|
||||||
|
|
||||||
void FramelessHelper::updateCursor()
|
void FramelessHelper::updateCursor()
|
||||||
{
|
{
|
||||||
if (isHoverResizeHandler())
|
if (isHoverResizeHandler()) {
|
||||||
setCursor(cursorForFrameSection(m_hoveredFrameSection));
|
setCursor(cursorForFrameSection(m_hoveredFrameSection));
|
||||||
|
} else {
|
||||||
|
unsetCursor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessHelper::updateMouse(const QPoint& pos)
|
void FramelessHelper::updateMouse(const QPoint& pos)
|
||||||
|
@ -239,6 +242,8 @@ void FramelessHelper::updateHoverStates(const QPoint& pos)
|
||||||
|
|
||||||
bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
{
|
{
|
||||||
|
bool filterOut = false;
|
||||||
|
|
||||||
if (object == m_window) {
|
if (object == m_window) {
|
||||||
switch (event->type())
|
switch (event->type())
|
||||||
{
|
{
|
||||||
|
@ -266,6 +271,8 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return filterOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
|
||||||
#include <QtCore/qobject.h>
|
#include <QtCore/qobject.h>
|
||||||
|
#include <QtCore/qsize.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
Q_GLOBAL_STATIC(FramelessHelper, framelessHelperUnix)
|
//Q_GLOBAL_STATIC(FramelessHelper, framelessHelperUnix)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void FramelessWindowsManager::addWindow(QWindow *window)
|
void FramelessWindowsManager::addWindow(QWindow *window)
|
||||||
|
@ -51,7 +51,7 @@ void FramelessWindowsManager::addWindow(QWindow *window)
|
||||||
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
framelessHelperUnix()->removeWindowFrame(window);
|
//framelessHelperUnix()->removeWindowFrame(window);
|
||||||
#else
|
#else
|
||||||
FramelessHelperWin::addFramelessWindow(window);
|
FramelessHelperWin::addFramelessWindow(window);
|
||||||
// Work-around a Win32 multi-monitor bug.
|
// Work-around a Win32 multi-monitor bug.
|
||||||
|
@ -165,7 +165,7 @@ void FramelessWindowsManager::removeWindow(QWindow *window)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
#ifdef FRAMELESSHELPER_USE_UNIX_VERSION
|
||||||
framelessHelperUnix()->bringBackWindowFrame(window);
|
//framelessHelperUnix()->bringBackWindowFrame(window);
|
||||||
#else
|
#else
|
||||||
FramelessHelperWin::removeFramelessWindow(window);
|
FramelessHelperWin::removeFramelessWindow(window);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue