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

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

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

        1. qtbug37581.zip
          2 kB
          Friedemann Kleint
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes