Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) QtExample22

 

QtQt CreatorLubuntuUbuntu

 

This Qt example shows a way to develop a transparent dialog.

 

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: ./CppQtExample22/CppQtExample22.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
#}

 

 

 

 

 

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

 

 

 

 

 

./CppQtExample22/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 resizeEvent(QResizeEvent *);

private:
  Ui::TransparentDialog *ui;
};

#endif // TRANSPARENTDIALOG_H

 

 

 

 

 

./CppQtExample22/transparentdialog.cpp

 

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

TransparentDialog::TransparentDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TransparentDialog)
{
  ui->setupUi(this);
}

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

void TransparentDialog::resizeEvent(QResizeEvent *)
{
  //Make all transparent, except for the label
  QRegion maskedRegion(ui->label->geometry());
  setMask(maskedRegion);
}

 

 

 

 

 

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