Search code examples
qtlightbox2

how to get a "lightbox" like behaviour in Qt


I have a Qt project where I'm using QGraphicsView framework, also I have popup windows on the scenes. (QDialogs)

When someone clicks on a certain button a popup window appears, and I'm invoking it with the .exec() method instead of .show() to make it the active one. Also I want to give it a visual effect like lightbox provides for html pages, so it would be obvious for the user too, that the background window won't communicate. Do you know any simple solution to make it work? or is it hard to implement in Qt? EDIT: I don't know if it's obvious of not, but it's a desktop application, not a web application.


Solution

  • Now I found another way to accomplish what I wanted. Like this:

    QWidget* mytranswidget = new QWidget(mybgwidget);
    mytranswidget->setStyleSheet( "background:transparent; background-color:rgba(0,0,0‌​,95)");
    mytranswidget->setWindowFlag(Qt::FramelessWindowHint);
    mytranswidget->setGeometry(mybgwidget->rect());
    mytranswidget->show();

    I'm doing it at the beginning of my popup widget's constructor so it's being drawn before draw my popup, so it will be shown in the right order.