简体   繁体   中英

Transparent QWebView on Mac OS X

I'm trying to display QWebView where the contents will have round corners, so I need transparent background in order to hide the original white corners. I'm using the "trick" I found here

This did not work for me so I added

this->view.setAttribute(Qt::WA_TranslucentBackground);

and now it works how it is supposed to on Linux(Ubuntu) and Windows, but not Mac OS X. Mac OS X just keeps displaying black corners. I tried setting stylesheet like this

this->view.setStyleSheet("background: transparent;");

or

this->view.setStyleSheet("background-color: none");

or

this->view.setStyleSheet("QWidget { background: transparent; }");

But nothing worked. Is there any way I can make that work? I'm using Qt 5.0.2.

Check out this code: https://github.com/pcmantinker/Tray-Notification-System/blob/master/traynotificationwidget.cpp

I made a project a while back for displaying notification widgets in the system tray across all platforms compatible with Qt.

The trick is to make nested widgets with the parent widget having no border and no background and the child widget will be your display widget which you can customize with QSS.

Here's some sample images of how it looks:
Windows 7
Windows 7的
Mac OS X Lion
Mac OS X Lion
Ubuntu
的Ubuntu
I hope this helps. Let me know if you have any questions.

I finally solved the problem by upgrading Qt from 5.0.2 to 5.1.0 . It's not optimal solution but it seems that there is a lot of regressions from 4.x to 5.0.x .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM