No window frame Qt - dithered analog mode Form

Original link: the Qt no window frame - dithered analog mode Form

I. Overview

With Qt development windows client interface is really a great tool, taking into account the performance speed is relatively good. Plus auxiliary qss, then a nice interface on goes without saying.

Want to make a beautiful interface, rewrite a title bar is essential, then we certainly need to use Qt to provide us with a borderless Qt :: FramelessWindowHint form properties. But after setting this property, it is a series of attendant problems, such as dragging the title bar of the need to engage ourselves; window zoom need to implement; the most terrible is that some of the modal form native jitter effect is not a.

Since the problem, then we have to find ways to solve.

Zoom and drag the window in earlier versions of Qt is to provide a supported file type, the author of this document was also second development, can provide richer functionality. Because little drag and zoom the relationship with this article, and therefore are not described here, interested students can go to the Qt no window frame - Support drag reduction is maximized here

In this article we'll talk about when the modal form pops up if you click on the application program interface other than non-modal window, how to achieve a flashing effect.

Just a flash of foreign exchange information, and if you want some other interactive effects can be self-fulfilling.

Second, the results show

As shown in FIG effect, make a simple effect

  1. When you click the main application, pop-up modal window border color changes have taken place to achieve a jitter effect.
  2. When you click the desktop, change the modal form also has a state of losing focus.

Third, the function realization

To achieve the effect of jitter window, you first need to understand the windows of the message ID, the message we want to know which windows to complete the flashing accept the results, the second is how to receive such a message native windows Qt.

windowws news

Learn windows message ID, readily open a search engine, enter a keyword Windows消息ID, and then be able to find a large number of articles devoted windwos news, bloggers here to find a list of news articles organize windows Windows message ID description , the basic message of the article the Chinese have notes, so reading is easier.

Then we will find such a message, we may be required, as shown in FIG.

Article 130 of the content, ID 86 is WM_NCACTIVATE message. Messages that are triggered when a window is actually its non-client area needs to be changed to display is active or inactive. Listen a bit mean, it seems that we need, then try chanting.

Qt message receiving Native

Since the lock message ID, then the next step is to receive the message, and then the UI interactivity response can be.

So the question is, Qt window how the message it receives a native windows!

The problem, of course not beat us. Qt why such a fire, not just because the library package is good, but it helps document more comprehensive. Next you should know what to do it, open the help file, and then search for the keyword nativeEv, if you do not know the specific name or function name of the function, the best fuzzy search.

Does not know the search, a search surprised, there are many original native message receiving function, as shown below no.

A total figure above has the following functions

  1. filterNativeEvent: install an event filter callback function
  2. installNativeEventFilter: install an event filter, the callback function is the fourth function
  3. nativeEvent: Native window event callbacks
  4. nativeEventFilter: Event Filter callback function, using the installation method 2

Here we see the card can be some confusion, it seems almost! In actual fact, but there are still other, interested students can take a look at what I wrote before several related articles, we are used to receive messages globally windows to achieve first off function, it is the specific point using the above method method 2+ 4 to complete.

  1. Custom Qt context menu of QLineEdit
  2. qt windows to capture the overall message
  3. Qt components of the stock - stock Retrieval - Support search results preview, mouse, keyboard

除过方法2和方法4搭配起来使用外,方法1和方法2也可以一起搭配使用,言外之意就是方法2是按照事件过滤器的,方法1和方法4只是事件过滤器的回调处理接口而已。

为什么这么说呢,大家可以来验证一下,还是打开帮助文档,我们输入关键字installNativeEventFilter,回车就会发现,事件过滤器可以被安装到两个对象上,一个是我们熟知的QCoreApplication,另外一个看着好像也会牛逼的样子,好像还是一个全局的抽象事件派发器。恭喜你,答对了,这两个对象都很牛逼,都能优先处理到Qt的全局事件。

本篇文章我们只是要实现一个模态窗体的抖动而已,因此就不需要大材小用了,我们使用QWidget的nativeEvent函数即可,同样能达到我们的目的。

大方向都定了,那么还等什么

打开vs,新建了一个demo。哐哐哐,就是一顿干。。。。

发现还真好使,窃喜中。。。

下面是实现的核心代码,由于是demo,所以写的比较粗糙,大家在写到项目里时最好能规范下代码。

bool XXX::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    if ("windows_generic_MSG" == eventType)
    {
        MSG * pMsg = reinterpret_cast<MSG *>(message);

        if (pMsg->message == WM_NCACTIVATE)
        {
            bool active = (bool)(pMsg->wParam);

            if (active)
            {
                setStyleSheet("border:2 solid blue;background:gray;");
            }
            else
            {
                setStyleSheet("border:2 solid red;background:gray;");
            }

            style()->unpolish(this);
            style()->polish(this);
        }
    }

    return  QDialog::nativeEvent(eventType, message, result);
}

重点强调

这里还需要说一点,有些同学按照文档操作了,调试时代码也走到相关位置了,但是发现没有效果,然后就开始怀疑人生了。

这里博主重点说几个可能出现错误的地方

  1. 我们的模态窗体一定要指定模态的父窗体是谁
  2. 窗体一定要设置上Qt::Dialog属性

第二点是非常关键的,很多同学都是没有设置这个属性,导致失去了效果。

四、相关文章

  1. Qt自定义的无边框Dialog 在点击其他窗口时处理闪烁效果
  2. Qt无边框窗体-最大化时支持拖拽还原
  3. Qt之自定义QLineEdit右键菜单
  4. qt捕获全局windows消息
  5. Qt之股票组件-股票检索--支持搜索结果预览、鼠标、键盘操作

值得一看的优秀文章:

  1. 财联社-产品展示
  2. 广联达-产品展示
  3. Qt定制控件列表
  4. 牛逼哄哄的Qt库





如果您觉得文章不错,不妨给个 打赏,写作不易,感谢各位的支持。您的支持是我最大的动力,谢谢!!!














很重要--转载声明

  1. 本站文章无特别说明,皆为原创,版权所有,转载时请用链接的方式,给出原文出处。同时写上原作者:朝十晚八 or Twowords

  2. 如要转载,请原文转载,如在转载时修改本文,请事先告知,谢绝在转载时通过修改本文达到有利于转载者的目的。


Guess you like

Origin www.cnblogs.com/swarmbees/p/11568821.html