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. Create overlay that grayscales widget behind
Qt 6.11 is out! See what's new in the release blog

Create overlay that grayscales widget behind

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 705 Views
  • 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.
  • H Offline
    H Offline
    Horia
    wrote on last edited by
    #1

    Hello I need some help with something I'm trying to do.

    I've got an image that has some color and that is inacessible for an overlay class that should create an overlay that would grayscale the image (to show it's deactived).

    All I've got now is an overlay widget that holds a QPainter rectangle that has a certain opacity and is black, as such :

          QPainter p{this};
          p.fillRect(rect(), {0, 0, 0, 200});
    

    But the colors of the image behind are still visible obviously as all it does is darkening the image widget.

    I am on Qt 5.12.5, c++, windows 10.

    I have seen some solutions with QML but I am sadly not using QML. Any directions or ideas would be great :-)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      If the image is shown in a single widget (like a QLabel), instead of an overlay (I have no solution for that), you can use QWidget::setGraphicsEffect() + QGraphicsColorizeEffect

      QGraphicsColorizeEffect* effect = new QGraphicsColorizeEffect(this);
      effect->setColor(Qt::gray);
      ui->label->setGraphicsEffect(effect);
      

      P.S. There's a note in the doc:

      Note: Graphics effects are not supported for OpenGL-based widgets, such as QGLWidget, QOpenGLWidget and QQuickWidget.

      Since you don't use QML, I think maybe that'll be fine.

      1 Reply Last reply
      5

      • Login

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