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. How to switch TranslucentBackground ?

How to switch TranslucentBackground ?

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

    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)));

    https://github.com/sonichy

    D 1 Reply Last reply
    0
    • sonichyS sonichy

      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)));

      D Offline
      D Offline
      Devopia53
      wrote on last edited by
      #2

      @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();
      [...]
      
      1 Reply Last reply
      1

      • Login

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