Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-37581

Qt 4.8, Windows: Custom Drawings Using PaintEvent & Setting widget attribute Qt::WA_Translucent, Not working On Windows if Qt::WindowTitleHint is set

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • P4: Low
    • None
    • 4.8.5
    • GUI: Painting
    • None
    • Windows 7(64 bit)

    Description

      Here is an example pasted below,
      if i tried to draw something on QWidget by overriding the PaintEvent(..) and setting Widget Attribute Qt::WA_Translucent nothing visible on Widget and becomes Complete Transparent as expected but drawing was not visible. i used Qt 4.8.1 & Qt 4.8.5 & Windows 7 (64 bit).

      But the same thing without modifying anything i just upgraded the Qt to latest version which is Qt 5.2.1 this example worked fine on the same platform.

      // mainwindow.cpp
      
      #include "mainwindow.h"
      #include <QPainter>
      
      MainWindow::MainWindow(QWidget *parent)
      : QWidget(parent)
      {
      this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
      this->setAttribute(Qt::WA_TranslucentBackground);
      }
      
      MainWindow::~MainWindow()
      {
      
      }
      
      void MainWindow::initTimer()
      {
      m_timer = new QTimer();
      connect(m_timer,SIGNAL(timeout()),this,SLOT(update()));
      m_timer->start(1000);
      }
      
      void MainWindow::paintEvent(QPaintEvent *pe)
      {
      QWidget::paintEvent(pe);
      QPainter painter(this);
      painter.beginNativePainting();
      QPen pen;
      pen.setStyle(Qt::SolidLine);
      pen.setColor(Qt::red);
      painter.setPen(pen);
      painter.drawLine(this->rect().topLeft(),this->rect().bottomRight());
      painter.endNativePainting();
      }
      
      // main.cpp
      
      #include <QtGui/QApplication>
      #include "mainwindow.h"
      
      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      MainWindow w;
      w.resize(500,500);
      w.initTimer();
      w.show();
      
      return a.exec();
      } 
      

      Attachments

        Issue Links

          Activity

            People

              kleint Friedemann Kleint
              kantharaju Kantharaju Dudda
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: