[Almost Solved]Translucent windows code works on Windows not working on Mac OS X. What changes are needed?
-
Hello,
I have been using this code to make a translucent top level window with several opaque buttons. This code works fine on Windows (msvc2010) but just gives opaque windows and buttons on Mac OS X (clang 64 bit).
"See screen shots here":https://www.dropbox.com/s/qw2bhwid0h35xsy/WinMacTransparency.png
I guess I must change some settings or attributes but I can't figure out which ones. If I use setWindowsOpacity() on the top window all of the children are also made transparent which is not what I want.
using a style sheet to set the alpha channel does not seem to work on the Mac like it does on Windows...I need to have transparency/opacity working on both platforms. I will be very grateful to anyone who can offer help with this.
Thanks.@
int main(int argc, char *argv[])
{
QApplication a(argc,argv);
QWidget *widget = new QWidget;
widget->setWindowFlags(Qt::FramelessWindowHint);
widget->setAttribute(Qt::WA_NoSystemBackground);
widget->setAttribute(Qt::WA_TranslucentBackground);
widget->setStyleSheet("background-color:rgba(0,0,0,50%);"); // sets tha base color and transparency
widget->setFixedSize(QSize(500,500));// this provides a backround to paint so we can see the window // the visble window takes the shape of this widget QLabel *label = new QLabel(widget); label->setFixedSize(500, 500); label->setStyleSheet("QLabel { border-radius: 20px; }"); // a widget for holding some content QWidget *contentWidget = new QWidget(label); contentWidget->setGeometry(200,200,200,200); // a layout widget for the content QGridLayout *layout = new QGridLayout(contentWidget); QToolButton *boxbutton1 = new QToolButton(contentWidget); boxbutton1->setFixedSize(QSize(32,32)); boxbutton1->setIconSize(QSize(32,23)); boxbutton1->setStyleSheet("color: black; background: white; border-radius: 5px;"); boxbutton1->setText("1"); layout->addWidget(boxbutton1); QToolButton *boxbutton2 = new QToolButton(contentWidget); boxbutton2->setFixedSize(QSize(32,32)); boxbutton2->setIconSize(QSize(32,32)); boxbutton2->setStyleSheet("color: black; background: white; border-radius: 5px;"); boxbutton2->setText("2"); layout->addWidget(boxbutton2); QToolButton *boxbutton3 = new QToolButton(contentWidget); boxbutton3->setFixedSize(QSize(32,32)); boxbutton3->setIconSize(QSize(32,32)); boxbutton3->setStyleSheet("color: black; background: white; border-radius: 5px;"); boxbutton3->setText("3"); layout->addWidget(boxbutton3); QToolButton *boxbutton4 = new QToolButton(contentWidget); boxbutton4->setFixedSize(QSize(32,32)); boxbutton4->setIconSize(QSize(32,32)); boxbutton4->setStyleSheet("color: black; background: white; border-radius: 5px;"); boxbutton4->setText("4"); layout->addWidget(boxbutton4); // an opaque button child of the label not the base window QToolButton *button = new QToolButton(label); button->setFixedSize(100, 100); button->setGeometry(20,20,20,20); button->setStyleSheet("QToolButton { color: black; background: white; border-radius: 5px; }"); button->setText("Quit"); widget->connect(button, SIGNAL(pressed()), &a, SLOT(closeAllWindows())); button->setShortcut(QKeySequence("Ctrl+Q")); button->setToolTip(a.tr("Exit the application (Qtrl-Q)")); button->setAutoRaise(true); widget->show(); return a.exec();
}
@ -
hi kenchan
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_NoSystemBackground,false);
setWindowFlags(windowFlags()| Qt::FramelessWindowHint);try the above code.
-
Thank you Vittal,
I tried your suggestion but it did not work. I still get an opaque background.
-
Hello,
This is an old post but I just wanted to update the status. I am know using Qt 5.1 on OSX and the transparency now works the same as on Windows.
I am very please about that. My thanks to all the folks making that happen!!
There is still one problem though... the transparent part goes haywire when I resize my window using the mouse. Might it be something to do with the double buffering??
Has anyone seen this kind of noise when transparent windows are animated? do I need to do anything special when I resize a transparent window on OSX?
Thanks.