问题描述
我对 qt 和 C++ 很陌生,但遇到了一个我似乎无法弄清楚的问题.当我单击主 ui 上的按钮时,我想打开一个无框且透明的窗口.当我按下主用户界面上的按钮时,我的代码可以打开一个新窗口,但我似乎无法让无框和透明部分工作.
I'm quite new to qt and c++ and I've encountered a problem that I can't seem to figure out. I'm wanting to open a frameless and transparent window when I click a button on the main ui. I've got the code working to open a new window when I press a button on the main ui but I can't seem to get the frameless and transparent part working.
这里是我为了学习这个而写的小程序的源码
Here is the source codes for the small program that I wrote to learn this
main.cpp
这里是 LearnWindow.h
Here is the LearnWindow.h
这里是learnwindow.cpp
Here is learnwindow.cpp
这里是transwindow.h
Here is the transwindow.h
这里是 transwindow.cpp
And here is transwindow.cpp
在不同的源代码中,您会看到注释掉的行,这是我尝试过的不同内容.在大多数情况下,问题是,如果我取消注释掉任何试图设置Qt::FramlessWindowHint"的行,程序会正常运行,但当我单击主用户界面上的按钮时永远不会打开新窗口.
In the different source codes you'll see commented out lines which is the different things that I've tried. For the most part the problem is, if I un-comment out any of the lines that try to set the "Qt::FramlessWindowHint" the program runs normally but never opens a new window when I click the button on the main ui.
如果我取消注释掉我设置Qt::WA_TranslucentBackground"的任何行,当在主用户界面中按下按钮时,新窗口将打开,但新窗口的背景是黑色的,而不是透明.
If I un-comment out any of the lines where I set the "Qt::WA_TranslucentBackground" the new window will open up when when the button is pressed in the main ui but the background of the new window is black, not transparent.
其他可能相关的信息:linux: ubunto 12.04qt 5.0.2(64 位)qt 创作者 2.7.1
Other info that may be pertinent: linux: ubunto 12.04 qt 5.0.2 (64-bit) qt creator 2.7.1
推荐答案
试试这个:
这篇关于无框透明窗qt5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!