GithubHelp home page GithubHelp logo

bringer-of-light / qt-nice-frameless-window Goto Github PK

View Code? Open in Web Editor NEW
778.0 31.0 195.0 2.47 MB

Qt Frameless Window for both Windows and OS X, support Aero Snap, drop shadow on Windows, and support Native Style such as round corner, drop shadow on OS X. Based on QMainWindow.

License: Other

QMake 15.91% C++ 63.34% Objective-C++ 20.75%
qt borderless draggable resizable cross-platform aero native drop-shadow support-aero-snap frameless

qt-nice-frameless-window's Introduction

Qt-Nice-Frameless-Window

Qt Frameless Window for both Windows and OS X, support Aero Snap, drop shadow on Windows, and support Native Style such as round corner, drop shadow on OS X. Based on QMainWindow.

基于 QMainWindow 实现的效果很好的 Qt 无边框窗口,支持 Windows 和 OS X 系统。在 Windows 上,支持窗口阴影、Aero 效果等;在 OS X 上,支持原生窗口样式,比如窗口圆角、窗口阴影、三个系统按钮(关闭、最小化、最大化)等。

996.icu LICENSE

Screenshots

Windows OS X
screenshot on Windows screenshot on OS X

How to use

Just use class "CFramelessWindow" as the base class instead of QMainWindow, and Enjoy!

Method 1

If you want to create a new project, then method 1 should be used.

  1. Create a new Qt subproject project say myproject.pro, just like Qt-Nice-Frameless-Window.pro.

  2. Copy folder "framelesswindow" and "projectinclude" to myproject path, the project directory structure should be looked like this:
    -myproject/
      -myproject.pro
      -myproject.pro.user
      -framelesswindow/
      -projectinclude/

  3. Add "SUBDIRS += framelesswindow" in myproject.pro and run qmake.

  4. Add a sub project say myapp.pro to myproject.

1 2
  1. Add "myapp.depends = framelesswindow" in myproject.pro and run qmake.
  2. Add "include (../projectinclude/common.pri)" in myapp.pro and run qmake.
  3. Right click on myapp.pro, and click "add library", a dialog will pop up, choose "interal library" and click next step again and again.
1 2 3
  1. After step 7 is done, something will be added into the myapp.pro file automaticly, run qmake again.
  2. Use class "CFramelessWindow" as the base class instead of QMainWindow.

Method 2

If you already have a project say myproject.pro, then method 2 should be used.

  1. Copy file "framelesswindow.h" and "framelesswindow.cpp" and "framelesswindow.mm" to myproject path.
  2. Add these lines to myproject.pro, then run qmake.
HEADERS += \
    framelesswindow.h

win32{
	SOURCES += \
		framelesswindow.cpp
}
macx{
    OBJECTIVE_SOURCES += \
		framelesswindow.mm
    LIBS += -framework Cocoa
}
  1. Use class "CFramelessWindow" as the base class instead of QMainWindow.
1 2

Windows Specific

  • The window have no title bar by default, so we can not move the window around with mouse. Inorder to make the window moveable, protected member function setTitleBar(QWidget* titlebar) should be called in the MainWindow's Constructor, the widget "titlebar" should be a child widget of MainWindow, and it will act exactly same as SYSTEM Title Bar.

  • Widget "titlebar" may has its own child widget, such as "close button" and "max button", and we can NOT move the window with "close button", which is what we want. However, a label widget "label1" on "titlebar" should not cover the moveable functionality, the protected member function addIgnoreWidget(QWidget* widget) is designed to deal with this kind of situation, just call addIgnoreWidget(ui->label1) in MainWindow's Constructor.

  • setResizeableAreaWidth(int width = 5) can set width of an invisible border aera, inside this aera, window can be resized by mouse.

  • setResizeable(bool resizeable) can set whether the window can be resized by mouse or not.

  • Exampleforwindows shows the general usage.

  • WARNING: resize()/geometry()/setGeometry()/frameGeometry()/frameSize()/x()/y()/.etc function will not works right when the Window is Maximized, try not to use any of these function when the Window is Maximized (If you really want to fix these bugs, feel free to contact Bringer-of-Light) . But these function setContentsMargins()/contentsMargins()/getContentsMargins/contentsRect() can always works right, so you can use them anytime. Generally , it's always a good idea to use Qt Layout Management System instead of hard-code layout Management to avoid potential size-like/pos-like issue.

OS X Specific

  • The whole window is draggable by default. setDraggableAreaHeight(int height) can set the draggable area height, in draggable area, window can be moved by mouse, (height = 0) means that the whole window is draggable.

  • Native style(three system button/ round corner/ drop shadow) works only on OS X 10.10 and later. If isNativeStyleOK() return false, we should implement three custom button(close/ min/ max).

  • If Native style is OK, three system button is provided by OS X. On OS X 10.10 and later, the default behavior of Zoom Button(Green Button) is to FullScreen the window, and this will cause some anoying issue: when the window returns to normal size from fullscreen state, the System Title Bar show again! As a result, CFramelessWindow override the behavior of Zoom Button to Maximized (Not FullScreen) the window.

  • If Native style is OK, the default behavior of close button is to quit the application. If we want to hide the app instead of quit, use setCloseBtnQuit(false). Be carefull that after set this to false, we can NOT revert it to true again! And this funciton should NOT be called more than once!

  • If Native style is OK, all there system button can be disabled by setCloseBtnEnabled(false), setMinBtnEnabled(false), setZoomBtnEnabled(false).

  • Exampleformac shows the general usage.

Platform

  • Tested with Qt5.9.2.
  • Tested on Windows 7 (with visual studio 2015) , Windows 10 (with visual studio 2015), OS X 10.10.2.

Acknowledge

qt-nice-frameless-window's People

Contributors

bringer-of-light avatar darkshinz avatar espotek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qt-nice-frameless-window's Issues

problem in window with Round corners

Hi, thanks for your great job, I only have one problem
im trying to create a program with round corners
image
but the problem is look like your code add some kind of hover in window (as you can see White things in all four corner of window)
there is anyway to fix it??
thanks

父窗口不能接收到WM_GETMINMAXINFO、WM_NCCALCSIZE、WM_NCHITTEST

父窗口:parentDialog
子窗口:childDialog

第一种情况:
父窗口parentDialog使用以下方法创建子窗口
childDialog = new ChildDialog();//父窗口创建子窗口:没有指定了parent
父窗口parentDialog的事件处理方法nativeEvent,能接收到WM_GETMINMAXINFO、WM_NCCALCSIZE、WM_NCHITTEST消息

第二种情况:
父窗口parentDialog使用以下方法创建子窗口
childDialog = new ChildDialog(this);//父窗口创建子窗口:指定了parent
父窗口parentDialog的事件处理方法nativeEvent,不能接收到WM_GETMINMAXINFO、WM_NCCALCSIZE、WM_NCHITTEST消息

win7 home basic版本下无法使用

谢谢你做的这么好的一个lib,在win10上体验非常非常棒。
目前的实现依赖dwmapi.dll
而在win7 home basic版本里是没有这个dll的,所以在win7 home basic版本下用的时候,鼠标移动到关闭按钮上时会出现操作系统自带的关闭按钮。

Can't move window to second screen

Hold down the left mouse button press and hold the left mouse button to move the window to the second screen the release of the mouse, and then click on the title bar to move the window, can not move

Err msg: QMainWindow::getContentsMargins(left,top,right,bottom);

G:\st_git\dragWindow\dragWinDemo\Qt-Nice-Frameless-Window\framelesswindow\framelesswindow.cpp:270: error: C2039: "getContentsMargins": 不是 "QMainWindow" 的成员
F:\QT_6.2\6.2.3\msvc2019_64\include\QtWidgets\qmainwindow.h(60): note: 参见“QMainWindow”的声明

win10自动隐藏任务栏后,我们的窗口最大化后,无法调出任务栏

win10开启自动隐藏任务栏后,
1、鼠标移入到屏幕最下排,会自动浮现出任务栏。
2、但Cframelesswindow最大化后,鼠标移入屏幕最下排,不会自动浮现出任务栏。

原因是在第一种情况下,软件最大化了,但最下排还是预留了2个像素。比如说屏幕分辨率是1366768。在这种情况下软件占据的屏幕像素为:1366766
但在第二种情况下,Cframelesswindow最大化后占据屏幕像素还是:1366*768

我已经把我fork的仓库删除了

您现在这个版本的代码仓库已经比我自己那个修改版的完善很多了,与其继续修补我那个定制版,还不如直接用您的来得划算,所以我就把我那个fork来的仓库删了,决定直接用您这个仓库。LICENSE我会保留的,您放心。

缺少#include <GdiPlusColor.h>,应该如何配置?

导入了framelesswindow.cpp文件之后发现缺少了<GdiPlusColor.h>,我下载了一个GDIPLUS文件,里面有一个include文件夹(包含了<GdiPlusColor.h>和很多其他的头文件)和一个lib文件夹(里面有一个GdiPlus.lib文件)请问有人清楚应该如何配置吗,是在visual studio中配置吗,还是通过Qt?我装的是visual studio 2017, Qt版本也是5.9.2。

Support system menu when clicking on top left corner of frameless window on Windows

So glad to see this project solving the problem of customising window title bar using native ways for both macOS and Windows! And, from a Chinese friend :) 这个项目太棒了!

I had a quick test on Windows and found all worked well except one feature seemed missing. When we click the top left corner of a standard application window, it normally shows a system menu like this:
screen shot 2018-09-24 at 12 11 52 pm
And this:
screen shot 2018-09-24 at 12 11 01 pm
As shown above, Adobe Illustrator for Windows uses a custom window title bar and has the system menu.

Just wondering if it's possible to add the same support in this project?

doesn't support Qt HighDpi on Windows OS

when (Qt::AA_EnableHighDpiScaling) is enabled, after set the WindowsOS system custom scale to 125% / 150% / 200%, the dragable area of the framelesswindow titlebar breaks.

menuBar 使用疑问

你好,请问一下,我使用了 menuBar,然后把这个 menuBar 设置为窗口的“titleBar”,拖动 menuBar 可以控制窗口移动,但是怎么让 menuBar 里面的菜单可以响应?我试了事件过滤器也毫无反应。

// exampleforwindows/mainwindow.cpp 文件的开头部分

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QRect>

MainWindow::MainWindow(QWidget *parent) :
    CFramelessWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
#ifdef Q_OS_WIN
    //feel free to change this number to see how it works
    setResizeableAreaWidth(8);

    //set titlebar widget, wo we can drag MainWindow by it
// 删除titleBar,并在ui中把horizontalLayout拿出来放到一个dockWidget,
// 是为了下面可以把这一堆按钮放到menuBar中。
//    setTitleBar(ui->widgetTitlebar);
    setTitleBar(menuWidget()); // 让menuBar作为“标题栏”
    menuWidget()->setLayout(ui->horizontalLayout); // 把一堆按钮放上去
// ......其他代码......

setResizeable(true)的情况下原生按钮出现

在setResizeable(true)以后最小化、最大化和关闭按钮会重新出现。一般是在鼠标移动到窗口边框时重绘出的,请问怎样可以解决这个问题呢?
setResizeable(false)时不存在此情况。

Vertical bar on secondary screen when window is maximized

When maximizing the window, my secondary screen displays a grey vertical bar of about ten pixels on the side towards the other screen.
This happens only with showMaximized(), not showFullscreen().

If someone knows about this issue or even has a solution, I would appreciate a hint. I'm using Windows 10, Version 21H1. One monitor is 1920x1080px, the other 1680x1050px so there is some scaling involved.

显示界面不正确

为什么在windows10上面跑显示的是mac的界面?有什么地方需要设置吗

win7 + qt5.8.0显示问题

你好, 在win7+qt5.8.0环境下,测试发现显示功能异常,是个空白面板,没有显示出任何按钮. 请问是什么原因导致的

QGraphicsView and QGLWidget

Hi, I try to use your Nice Frameless Window, but with a QGraphicsView.

Indeed, the content of my MainWindow, is juste a QGraphicsView.

To be able to optimize the performance of my GraphicsView, I use an openGL Viewport with :

ui->graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

When I add this line, then we can't move the MainWindows, and the "Hover" on button didn't work too.

Thanks

MacOS如何将窗口设置成模态窗口?

我将是将CFramelessWindow 继承自QWidget
然后设置
this->setAttribute(Qt::WA_ShowModal, true);
this->setWindowModality(Qt::ApplicationModal);
这部分代码 窗口的标题栏又出来了。

win7+qt5.8.0 + vs2013 按钮失灵

你好, 在该配置环境下, 最小化和最大化,退出按钮没有作用,点击的时候会闪现出默认的最小,最大化图标.

Setting fixed size on MainWindow makes the window undraggable. macOS. Qt 5.14.2

Using the CFramelessWindow in my project, if I try to set a fixed window size or set the maximum window size at all, I can no longer move the window.

Can be recreated by opening a new project, importing the framelesswindow.h, framelesswindow.cpp, and framelesswindow.mm, then setting CFramelessWindow, then try either setting maximum window size in designer, or use something like setFixedSize(w,h).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.