Making a translucent window, opaque contents
-
In summary use the stylesheet way of allowing the properties to child or not. One way of doing is that
Use the setObjectName("myObjectName") then use object name selector # in the css. -
ok so this is what I have:
@mainView::mainView(QWidget *parent)
: QMainWindow(parent)
{
this->setWindowOpacity(0.8);@It sets the mainView and everything within it to 0.8 opacity. How can I set it to that opacity, but keep all the contents at 1.0 opacity?
-
Try this.
@ this->setObjectName("myname");
QString style = "QMainWindow#myname { opacity:0.8 }";
this->setStyleSheet(style);@ -
I tried this and it works. It may be issue with your Window Size. Just try with following code.
@
this->setObjectName("myname");
QString style = "QMainWindow#myname { background-color: yellow }";
this->setStyleSheet(style);QPushButton *button = new QPushButton("Hello"); button->setObjectName("mybutton"); QString style1 = "QPushButton#mybutton { color: red }"; button->setStyleSheet(style1);@
-
i don't know what you want exactly, but making a window background transparent is only possible when you do the following:
@
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(new QComboBox);
layout->addWidget( new QSlider );
QWidget* mainWidget = new QWidget;
mainWidget->setLayout(layout);QMainWindow mainWin; mainWin.setObjectName("main"); mainWin.setCentralWidget( mainWidget ); mainWin.setWindowFlags(Qt::FramelessWindowHint); //<<<<<<<<< mainWin.setAttribute(Qt::WA_TranslucentBackground); //<<<<<<<<< mainWin.setStyleSheet( "QMainWindow#main {" "background: transparent;" "}" ); mainWin.show();
@
Note the setting of the window flags and widget attribute.