Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) QtExample21

 

QtQt CreatorLubuntuUbuntu

 

This Qt example shows a way to develop a transparent-like dialog. The trick used is to take a screenshot of the desktop before the dialog is shown. The illusion fades if the dialog is moved.

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppQtExample21/CppQtExample21.pro

 

exists(../../DesktopApplication.pri) {
  include(../../DesktopApplication.pri)
}
!exists(../../DesktopApplication.pri) {
  QT += core gui
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  TEMPLATE = app

  CONFIG(debug, debug|release) {
    message(Debug mode)
  }

  CONFIG(release, debug|release) {
    message(Release mode)
    DEFINES += NDEBUG NTRACE_BILDERBIKKEL
  }

  QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra

  unix {
    QMAKE_CXXFLAGS += -Werror
  }
}

exists(../../Libraries/Boost.pri) {
  include(../../Libraries/Boost.pri)
}
!exists(../../Libraries/Boost.pri) {
  win32 {
    INCLUDEPATH += \
      ../../../Projects/Libraries/boost_1_55_0
  }
}


SOURCES += \
  main.cpp \
  transparentdialog.cpp
HEADERS  += transparentdialog.h
FORMS    += transparentdialog.ui

#CONFIG += mobility
#MOBILITY =
#symbian {
#    TARGET.UID3 = 0xe7de6653
#    # TARGET.CAPABILITY +=
#    TARGET.EPOCSTACKSIZE = 0x14000
#    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
#}

 

 

 

 

 

./CppQtExample21/main.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QApplication>
#include "transparentdialog.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  TransparentDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

./CppQtExample21/transparentdialog.h

 

#ifndef TRANSPARENTDIALOG_H
#define TRANSPARENTDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QDialog>
#pragma GCC diagnostic pop

namespace Ui {
  class TransparentDialog;
}

class TransparentDialog : public QDialog
{
  Q_OBJECT

public:
  explicit TransparentDialog(QWidget *parent = 0);
  TransparentDialog(const TransparentDialog&) = delete;
  TransparentDialog& operator=(const TransparentDialog&) = delete;
  ~TransparentDialog();

protected:
  void paintEvent(QPaintEvent *);

private:
  Ui::TransparentDialog *ui;
  QPixmap m_pixmap;

private slots:
};

#endif // TRANSPARENTDIALOG_H

 

 

 

 

 

./CppQtExample21/transparentdialog.cpp

 

#include "transparentdialog.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QApplication>
#include <QDesktopWidget>
#include <QPainter>
#include "ui_transparentdialog.h"
#pragma GCC diagnostic pop

TransparentDialog::TransparentDialog(QWidget *parent)
  : QDialog(parent),
    ui(new Ui::TransparentDialog),
    m_pixmap(QPixmap::grabWindow(QApplication::desktop()->winId()))
{
  ui->setupUi(this);
}

TransparentDialog::~TransparentDialog()
{
  delete ui;
}

void TransparentDialog::paintEvent(QPaintEvent *)
{
  QPainter painter(this);
  painter.drawPixmap(
    this->rect(),
    m_pixmap,
    this->geometry());
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml