关于Qt5 WA_TranslucentBackground not displayed



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!"; //--&gt; 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:

  1. using Qt::FramelessWindowHint + Qt::WA_TranslucentBackground: QWidget not displayed
  2. using Qt::FramelessWindowHint + top level widget's background color and alpha channel < 255: QWidget not displayed
  3. using top level widget's background color and alpha channel < 255: QWidget not displayed
  4. 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值