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. Transluscent background of a QLabel in a QDialog. Qt 4.8.4

Transluscent background of a QLabel in a QDialog. Qt 4.8.4

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.8k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    silex92
    wrote on last edited by
    #1

    Hello,

    there is a modal frameless dialog with the whole screen geometry. It has a contant QPixmap on its background which it draws constantly in paintEvent.
    Inside the class there is rubber band drawer which inherits a QLabel (the whole screen geometry) which draws constantly a region defined by a set of elastic rectangles.
    Since in Qt 4.8 the contents propagation is the default behavior it should stay as it is. The only thing to add is
    setAttribute(Qt::WA_TranslucentBackground); to the rubber band drawer constructor. However, when the dialog is shown the QLabel background(rubber band drawer) is not transluscent. After I changed drawing of the pixmap in the dialog by making the pixmap transparent
    @void dialog::mk_transparent_pixmap()
    {
    pixmap = QPixmap(trigger_path).scaled(size());
    // Create new picture for transparent
    QPixmap transparent(pixmap.size());

    // Do transparency
    transparent.fill(Qt::transparent);
    QPainter p(&transparent);
    p.setCompositionMode(QPainter::CompositionMode_Source);
    p.drawPixmap(0, 0, pixmap);
    p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    // Set transparency level to 150 (possible values are 0-255)
    // The alpha channel of a color specifies the transparency effect,
    // 0 represents a fully transparent color, while 255 represents
    // a fully opaque color.
    p.fillRect(transparent.rect(), QColor(0, 0, 0, 180));
    p.end();
    
    // Set original picture's reference to new transparent one
    pixmap = transparent;
    

    }

    void dialog::draw_trigger()
    {
    if ( !is_transparent ) mk_transparent_pixmap(), is_transparent = true;
    QPainter painter(this);
    painter.drawPixmap(0,0,pixmap);
    }@
    it worked. Sure, since it is transparent.
    But how to achieve the goal in other ways? Making another modal dialog with transluscent background?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      have you tried the rubber band widget (QLabel) autoFillBackground to true?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        silex92
        wrote on last edited by
        #3

        When autoFillBackground is set to true and transluscent background is false it's of gray color. When the transluscent background is turned on it's of black color. Also black transparent (alpha=0) palette is used for an active window.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NicuPopescu
          wrote on last edited by
          #4

          bq. When autoFillBackground is set to true and transluscent background is false it’s of gray color.

          this should be ok, and use: setStyleSheet("background:transparent")

          1 Reply Last reply
          0

          • Login

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