Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Transparency effect between image and drawing
I want to give a transparency effect to an image, so the underlying drawing could be seen through. Has anybody used this king of effect, often visible in Windows desktop, with Qt ?
I'm grateful for any indication.
A Former User last edited by
@Furkas Hi! Are we talking about QWidgets or QtQuick? Do you want to make a whole window transparent or just an object within a window?
I'm talking about QWidgets, and I want just one transparent object, I think a QLabel may be cool.
see QGraphicsOpacityEffect class in case you want to make the whole widget transparent
Its also possible to add a linear opacity (gradient-like), but there is more work involved.
@raven-worx Thanks for your advice. It seems to be the right tool. But I have troubles with this class. I get an exception "Read acces violation" any time I try to call setGraphicsEffect() with this effect on a widget in my UI. I have not found in the manual what is the restriction.
It's ok if I add a QLabel outside of the UI.
hard to tell ... you're probably trying to accessing a uninitialized/deleted variable.
show some code pls.
@raven-worx Here the significant code :
MainWindow::MainWindow(QWidget *parent) :
imageLabel = new QLabel;
effect = new QGraphicsOpacityEffect; effect->setOpacity(0.6); //ui->imaLabel->setGraphicsEffect(effect); // Nok //ui->spinBoxGain->setGraphicsEffect(effect); // Nok //ui->pushButtonACAuto->setGraphicsEffect(effect); // Nok //imageLabel->setGraphicsEffect(effect); // ok ui->setupUi(this); //ui->imaLabel->setGraphicsEffect(effect); // Nok //ui->spinBoxGain->setGraphicsEffect(effect); // Nok //ui->pushButtonACAuto->setGraphicsEffect(effect); // Nok //imageLabel->setGraphicsEffect(effect); // ok ui->comboBoxAntType->addItem(tr("Antenne F1")); ui->comboBoxAntType->addItem(tr("Antenne F2")); ui->comboBoxAntType->addItem(tr("Antenne F3")); connect(ui->comboBoxAntType, SIGNAL(currentIndexChanged(int)), SLOT(on_ComboChanged(int)));
I think UI is not available before the call to setupUI(), but it's the same after.
yes indeed as you said, dont access any member of the ui variable before calling setupUi() on it.
Also - as the docs of QWidget::setGraphicsEffect() are clearly stating - you cannot reuse a graphicseffect for multiple widgets.
@raven-worx I noted. So, I tried one after another.