Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Transparency effect between image and drawing
Qt 6.11 is out! See what's new in the release blog

Transparency effect between image and drawing

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Furkas
    wrote on last edited by
    #1

    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.

    ? 1 Reply Last reply
    0
    • F Furkas

      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.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @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?

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Furkas
        wrote on last edited by
        #3

        @Wieland,
        I'm talking about QWidgets, and I want just one transparent object, I think a QLabel may be cool.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          F 1 Reply Last reply
          0
          • raven-worxR raven-worx

            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.

            F Offline
            F Offline
            Furkas
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              hard to tell ... you're probably trying to accessing a uninitialized/deleted variable.
              show some code pls.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              F 1 Reply Last reply
              0
              • raven-worxR raven-worx

                hard to tell ... you're probably trying to accessing a uninitialized/deleted variable.
                show some code pls.

                F Offline
                F Offline
                Furkas
                wrote on last edited by
                #7

                @raven-worx Here the significant code :
                #include <QMessageBox>
                #include <QStandardPaths>
                #include <QFileDialog>
                #include <QImageReader>
                #include <QTimer>
                #include <QtWidgets>

                #include "radararea.h"
                #include "mainwindow.h"
                #include "ui_mainwindow.h"

                MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
                {
                imageLabel = new QLabel;
                imageLabel->setBackgroundRole(QPalette::Base);
                imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
                imageLabel->setScaledContents(true);

                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.

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  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.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  F 1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    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.

                    F Offline
                    F Offline
                    Furkas
                    wrote on last edited by
                    #9

                    @raven-worx I noted. So, I tried one after another.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved