Qlabel with transparent mask does not update background?



  • Hallo everyone,
    I'm a noob for QT and I'm trying to develop a program for my research work.

    I'm trying to produce a QLabel with a transparent background and a transparent mask, in order to be able to click "through" the background of the label and see what happens.
    I managed to set a transparent mask for a label but then its background is not updated, so if something happens below the label I do not see it happening.

    Please, help! ?(

    Here is my code:
    @
    #include <QApplication>
    #include <QtGui>

    void delay()
    {
    QTime dieTime= QTime::currentTime().addSecs(5);
    while( QTime::currentTime() < dieTime )
    QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }

    int main(int argc, char* argv[])
    {
    QApplication a(argc, argv);
    QMainWindow* window = new QMainWindow;
    QPixmap pixmap(40,40);

    //window->setWindowFlags(Qt::WindowStaysOnTopHint);
    pixmap.fill(Qt::transparent);
    QPainter p(&pixmap);
    p.setPen(Qt::blue);
    p.drawLine(5,5, 40, 40);
    p.end();
    QLabel label;
    label.setPixmap(pixmap);
    label.setMask(pixmap.mask());
    label.setWindowFlags(Qt::WindowStaysOnTopHint);
    label.setAttribute(Qt::WA_TranslucentBackground);
    // label.setAutoFillBackground(true);
    label.show();
    //QCursor::setPos(40, 40);
    delay();

    label.move(40,40);
    return a.exec();
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.