Use Qt to draw profiled forms and use qt to draw profiled forms.

Source: Internet
Author: User

Use Qt to draw profiled forms and use qt to draw profiled forms.

   

The special form is an irregular form. Generally, png images are used. Generally, the special form is drawn in two steps:

1. Set the mask area
2. Draw Images

 

   

Use the transparent part of the png image as the mask area, and then draw the image, so that we can see a graph that only draws the non-transparent part, for example, to draw a butterfly (Butterfly is translucent), the effect is as follows:

   

  1: #include <QWidget>
  2: class TransDialog : public QWidget
  3: {
  4:     Q_OBJECT
  5: public:
  6:     explicit TransDialog(QWidget *parent = 0);
  7:     void paintEvent(QPaintEvent *event) ;
  8: private:
  9:     QPixmap m_Pixmap;
 10: };
 11: 

Cpp file:

  1: #include "transdialog.h"
  2: #include <QBitmap>
  3: #include <QPalette>
  4: #include <QPaintEvent>
  5: 
  6: TransDialog::TransDialog(QWidget *parent) :
  7:     QWidget(parent,Qt::FramelessWindowHint)
  8: {
9: // make the program background translucent
 10:     this->setWindowOpacity(0.5);
11: // load a transparent image in some areas as a program interface
 12:     m_Pixmap.load("hudie.png");
 13:     resize(640, 480);
14: // keep the image as the page size
 15:     m_Pixmap = m_Pixmap.scaled(size());
16: // set Automatic Filling
 17:     setAutoFillBackground(true);
 18: 
19: // key to the irregular window. Set the transparent area of the image as the penetrating area.
 20:     setMask( m_Pixmap.mask() );
 21: 
 22: }
 23: 
 24: void TransDialog::paintEvent(QPaintEvent *event)
 25: {
26: // draw the background image
 27:     QPalette bgPalette = this->palette();
 28:     bgPalette.setBrush(QPalette::Background,m_Pixmap);
 29:     this->setPalette(bgPalette);
 30: }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.