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. Custom widget background is not opacity / transparent.
Forum Updated to NodeBB v4.3 + New Features

Custom widget background is not opacity / transparent.

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

    I created a CustomWidget class:
    CustomWidget.h:

    #include <QWidget>
    #include <QPainter>
    
    class CustomWidget : public QWidget
    {
      Q_OBJECT
    public:
      explicit CustomWidget(QWidget *parent = nullptr);
    
      void paintEvent(QPaintEvent* event);
    
    signals:
    
    public slots:
    };
    

    CustomWidget.cpp:

    #include "customwidget.h"
    
    CustomWidget::CustomWidget(QWidget *parent) : QWidget(parent)
    {
      this->setWindowFlag(Qt::FramelessWindowHint);
    }
    
    void CustomWidget::paintEvent(QPaintEvent* event)
    {
      if (this->isActiveWindow())
      {
        QPainter painter(this);
        painter.setPen(Qt::green);
        painter.setBrush(QBrush(QColor(69, 232, 32, 100)));
        painter.drawRect(rect());
      }
    }
    

    When I compile and run this codes on Linux (KDE Neon), I see correct widget with color (color is green = 69, 232, 32) but opacity (alpha = 100) is not working. Here is picture:
    This is not correct.
    How can I create transparent or opacity widgets? Is this a bug?
    Also, I can see transparent widgets if I can create opacity / transparent widget but can't use background (I mean I can't intervene objects that behind of the widget. You know that screencast applications records all screen and we can use screen). Can I create widgets like this?
    Thanks.

    jsulmJ 1 Reply Last reply
    0
    • I Ibrahim

      I created a CustomWidget class:
      CustomWidget.h:

      #include <QWidget>
      #include <QPainter>
      
      class CustomWidget : public QWidget
      {
        Q_OBJECT
      public:
        explicit CustomWidget(QWidget *parent = nullptr);
      
        void paintEvent(QPaintEvent* event);
      
      signals:
      
      public slots:
      };
      

      CustomWidget.cpp:

      #include "customwidget.h"
      
      CustomWidget::CustomWidget(QWidget *parent) : QWidget(parent)
      {
        this->setWindowFlag(Qt::FramelessWindowHint);
      }
      
      void CustomWidget::paintEvent(QPaintEvent* event)
      {
        if (this->isActiveWindow())
        {
          QPainter painter(this);
          painter.setPen(Qt::green);
          painter.setBrush(QBrush(QColor(69, 232, 32, 100)));
          painter.drawRect(rect());
        }
      }
      

      When I compile and run this codes on Linux (KDE Neon), I see correct widget with color (color is green = 69, 232, 32) but opacity (alpha = 100) is not working. Here is picture:
      This is not correct.
      How can I create transparent or opacity widgets? Is this a bug?
      Also, I can see transparent widgets if I can create opacity / transparent widget but can't use background (I mean I can't intervene objects that behind of the widget. You know that screencast applications records all screen and we can use screen). Can I create widgets like this?
      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ibrahim Try https://doc.qt.io/qt-5/qpainter.html#setOpacity

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      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