关于Qt5 WA_TranslucentBackground not displayed
来源:互联网 发布:独孤信印 淘宝 编辑:程序博客网 时间:2024/06/04 01:02
I'm on Windows 7 and I'm having an issue with Qt::WA_TranslucentBackground as well. My app is not crashing, but if I set that attribute to true, then my widget is not displayed at all. Im setting the widget as
4.8.1 was working just fine, didnt change anything, there must be something broken in Qt5 with that behaviour.
Any ideas?
I hope someone can fix this since im porting my application to Qt5 and this tricks is one of the "nice" visual details of it and is not working now.
ej:
@Widget::Widget(QWidget *parent) :
QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
{
ui.setupUi(this);
setAttribute(Qt::WA_TranslucentBackground,true);QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect();effect->setXOffset(0.0);effect->setYOffset(0.0);effect->setColor(Qt::gray);effect->setBlurRadius(6);ui.Container->setGraphicsEffect(effect);shorcut.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Space));setVisible(false);connect(&shorcut, SIGNAL(activated()), this, SLOT(shortcutActivated()));
}
void Widget::shortcutActivated()
{
if (ui.Container->isVisible())
ui.Container->hide();
else
{
show();
raise();
activateWindow();
ui.Container->show();
}
qDebug() << "shortcut activated!"; //--> i get this, but the widget is not been displayed
}
Ok i think i found something. This is probably a bug.
I removed the setAttribute(Qt::wA_TranslucentBackground); and of course that works fine and the widget is displayed. Then i changed the style of the container widget to have a background color with an alpha channel of 100. BUM! widget is not longer been displayed.
As long as you use 255 o simple rgb color, it works, but when you introduce some transparency, alpha channel lower than 255, that breaks the display. So it might have nothing to do with the Qt::WA_TranslucentBackground, but with the alpha channel of the top level widget.
so, to sum up:
- using Qt::FramelessWindowHint + Qt::WA_TranslucentBackground: QWidget not displayed
- using Qt::FramelessWindowHint + top level widget's background color and alpha channel < 255:QWidget not displayed
- using top level widget's background color and alpha channel < 255: QWidget not displayed
- using Qt::FramelessWindowHint + top level widget's background color and alpha channel = 255:OK QWidget displayed
Ok... i got it working... but there's some strange thing going on.
If i create the widget manually everything is good. But i was using a simple ui file created with designer. Then if i set the attribute after calling ui->setupUi(this) then the widget is not displayed. If i set the attribute before calling setupUi, that works. Strange isnt it?
I have the same issue on win7. My painting is actually done in a contained QGraphicsView and the QDialog Container widget is transparent to get rounded corners. I verified that removing the call to setupUi (which in my case does nothing anyway) fixes the issue (the widget now displays the contained QGraphicsView).
Yep, aparently setAttribute has to be called before calling setupUi, at least for the WA_TranslucentBackground atribute. Not sure why, maybe someone from Qt have a better explanation.
Im still having issues when using translucent attribute. My app is like a menu bar that when you click on a button it slides down a widget that gives you options depending on the button you've clicked.
When i click any button, suddenly the rest of the buttons dissapear, as well as the shadow effect that surrounds the widget. i can only get back to normal if i repaint the whole app or minimize/restore it. Also because of this weird behaviour sometimes i get a crash because im storing those sliding widgets in QScoopedPointers and when trying to acces them when they are supposed to be displayed the pointer is null. This doesnt happen at all if i disable the WA_TransulcentBackground attribute.
Something has changed from 4.8.1 to 5.0.1 on the widget handling when translucency is used. since everything was working fine. And this is a pretty annoying bug, that needs to be fixed, otherwhise all applications using this thing will eventually suffer from weird behaviour.
Is anyone from the Qt team taking a look in this forums? Help will be much appreciated.
Thanks for superpacko. Pefect resolution!!
[quote author="superpacko" date="1361394223"]Ok... i got it working... but there's some strange thing going on.
If i create the widget manually everything is good. But i was using a simple ui file created with designer. Then if i set the attribute after calling ui->setupUi(this) then the widget is not displayed. If i set the attribute before calling setupUi, that works. Strange isnt it?[/quote]
https://forum.qt.io/topic/23783/qt5-can-t-set-wa_translucentbackground-to-a-qwidget/13
- 关于Qt5 WA_TranslucentBackground not displayed
- Note 910879 - Attributes are not displayed in Query Designer
- JMeter - Why response data is not displayed in .jtl file
- zabbix server is not running: the information displayed may not be current
- zabbix server is not running: the information displayed may not be current.
- Zabbix server is not running: the information displayed may not be current.
- Zabbix server is not running:the information displayed may not be current
- zabbix监控报错zabbix server is not running: the information displayed may not be current
- zabbix server 报错 zabbix server is not running: the information displayed may not be current
- 关于Qt5的录音
- WARNING: FacesMessage(s) have been enqueued, but may not have been displayed
- SP2-0678: Column or attribute type can not be displayed by SQL*Plus
- Do not concatenate text displayed with setText. Use resource string with placeholders. 提示
- android基础--TextView.Do not concatenate text displayed with setText. Use resource string with placeho
- Do not concatenate text displayed with setText,use resource string with placeholders.
- Do not concatenate text displayed with 'setText'. Use resource string with placeholders.
- Do not concatenate text displayed with setText. Use resource string with placeho
- zabbix监控报错zabbix server is not running: the information displayed may not be current的解决
- DP 专题
- iOS中关于bounds、size、origin的区别
- Andriod学习笔记:仿美图秀秀首页手柄下拉功能实现(二)
- MAVEN Dynamic Web Module 3.0 requires Java 1.6 or newer.
- 微信公众账号开发,将消息转发到指定客服java 代码
- 关于Qt5 WA_TranslucentBackground not displayed
- App Store Review Guidelines中文版-上部
- Android 断点续传下载功能实现
- 变量的声明与定义
- 导航布局(HTML+CSS+JavaScript)
- 背包专题
- android学习笔记-布局
- Android官方导航栏ActionBar(二)—— Action View、Action Provider、Navigation Tabs的详细用法
- 2015年第一季度总结