How to switch TranslucentBackground ?



  • setAttribute(Qt::WA_TranslucentBackground, true) can change normal background to translucent, but can not change translucent to normal.
    close() then open(), update() are helpless too.

    void MainWindow::changeBackground(bool on){
    qDebug() << on;
    setAttribute(Qt::WA_TranslucentBackground,on);
    }

    QAction *backgroundAction;
    backgroundAction=new QAction("背景透明",traymenu);
    backgroundAction->setCheckable(true);
    connect(backgroundAction, SIGNAL(toggled(bool)),this, SLOT(changeBackground(bool)));



  • @sonichy

    If it is possible to change from a normal state to a translucent state, like this:

    [...]
    setAttribute(Qt::WA_TranslucentBackground, on);
    if (on) {
        setWindowFlags(windowFlags() | Qt::FramelessWindowHint); // if MS Windows
    }
    else {
        setWindowFlags(windowFlags() ^ Qt::FramelessWindowHint); // if MS Windows
        setAttribute(Qt::WA_NoSystemBackground, on);
    }
    show();
    [...]
    

Log in to reply
 

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