Qt 9 palace map implements the window shadow and qt palace Map window shadow

Source: Internet
Author: User
Tags 0xc0

Qt 9 palace map implements the window shadow and qt palace Map window shadow

<Pre name = "code" class = "cpp"> # include <QBoxLayout> # include <QPalette> # include <QGraphicsDropShadowEffect> # include <QDebug> # include <QSizePolicy> # include <QPainter> # include "bfwidget. h "// users // ----------- Created with 010 Editor ----------- // ------ www.sweetscape.com/010editor/ ------ // File: G: \ project \ Sample \ ShadeWindow \ box-shadow.png // Address: 0 (0x0) // Size: 588 (0x24C) // returns unsigned char _ hexData [588] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,0x00, 0x00, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x1D, 0x08, 0x06, 0x00, 0x00, 0x00, 0x56, 0x93, 0x67, 0x0F, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47,0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00,0x00, 0x06, 0x62, 0x4B, 0x47, 0x44, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xA0, 0xBD, 0xA7, 0x93,0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59, 0x73,0x00, 0x00, 0x0D, 0xD7, 0x00, 0x00, 0x0D, 0xD7, 0x01, 0x42, 0x28, 0x9B, 0x78, 0x00, 0x00, 0x00,0x07, 0x74, 0x49, 0x4D, 0x45, 0x07, 0xDA, 0x03, 0x0A, 0x01, 0x3B, 0x39, 0x35, 0x19, 0x02, 0x5A, 0x00, 0x00, 0x00, 0x22, 0x74, 0x45, 0x58, 0x43, 0x6F, 0x6D, 0x6D, 0x65, 0x6E, 0x74, 0 x, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4D, 0x50, 0x20, 0x6F, 0x6E, 0x20, 0x61, 0x20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C, 0xB4, 0xD2, 0x77, 0x63, 0x95, 0x06, 0x75, 0xD4, 0x8D, 0x72, 0x0B, 0x7C, 0xE8, 0x7B, 0x6B, 0xAC, 0xE9, 0x92, 0x9B, 0xC3, 0x56, 0x7D, 0x87, 0x78, 0x21, 0xB5, 0x66, 0x94, 0xA8, 0x52, 0x75, 0xC5, 0x3B, 0x52,0x37, 0xAF, 0xC9, 0x3B, 0xEE, 0x6F, 0xDF, 0x06,0x83, 0xFB, 0xC3, 0x7B, 0xEF, 0x61, 0xCF, 0x8E, 0x72, 0xC3, 0x77, 0x63, 0xFC, 0xCB, 0x7C, 0x01, 0x3F, 0xD0, 0xC3, 0x34, 0xFA, 0xD4, 0x35, 0x7A, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82}; const QPixmap _ DrawNinePatch (QSize szDst, const QPixmap & srcPix) {// draw the background image, QPixmap dstPix (szDst); dstPix. fill (QColor (255,255,255, 0); QPainter painter; painter. begin (& dstPix); int nW = szDst. width (); int nH = szDst. height (); int nWBg = srcPix. width (); int nHBg = srcPix. height (); QPoint m_ptBgLT (10, 10); QPoint m_ptBgRB (19, 19); QPoint ptDstLT (m_ptBgLT.x (), m_ptBgLT.y ()); QPoint ptDstRB (nW-(nWBg-m_ptBgRB.x (), nH-(nHBg-m_ptBgRB.y (); // LTpainter. drawPixmap (QRect (0, 0, ptDstLT. x (), ptDstLT. y (), srcPix, QRect (0, 0, m_ptBgLT.x (), m_ptBgLT.y (); // MTpainter. drawPixmap (QRect (ptDstLT. x (), 0, ptDstRB. x ()-ptDstLT. x (), ptDstLT. y (), srcPix, QRect (m_ptBgLT.x (), 0, m_ptBgRB.x ()-m_ptBgLT.x (), m_ptBgLT.y (); // RTpainter. drawPixmap (QRect (ptDstRB. x (), 0, nW-ptDstRB. x (), ptDstLT. y (), srcPix, QRect (m_ptBgRB.x (), 0, nWBg-m_ptBgRB.x (), m_ptBgLT.y (); // LMpainter. drawPixmap (QRect (0, ptDstLT. y (), ptDstLT. x (), ptDstRB. y ()-ptDstLT. y (), srcPix, QRect (0, m_ptBgLT.y (), m_ptBgLT.x (), m_ptBgRB.y ()-m_ptBgLT.y (); // matrix. drawPixmap (QRect (ptDstLT. x (), ptDstLT. y (), ptDstRB. x ()-ptDstLT. x (), ptDstRB. y ()-ptDstLT. y (), srcPix, QRect (m_ptBgLT.x (), m_ptBgLT.y (), m_ptBgRB.x ()-convert (), convert ()-m_ptBgLT.y (); // RMpainter. drawPixmap (QRect (ptDstRB. x (), ptDstLT. y (), nW-ptDstRB. x (), ptDstRB. y ()-ptDstLT. y (), srcPix, QRect (m_ptBgRB.x (), m_ptBgLT.y (), nWBg-m_ptBgRB.x (), merge ()-m_ptBgLT.y (); // LBpainter. drawPixmap (QRect (0, ptDstRB. y (), ptDstLT. x (), nH-ptDstRB. y (), srcPix, QRect (0, m_ptBgRB.y (), m_ptBgLT.x (), nHBg-m_ptBgRB.y (); // MBpainter. drawPixmap (QRect (ptDstLT. x (), ptDstRB. y (), ptDstRB. x ()-ptDstLT. x (), nH-ptDstRB. y (), srcPix, QRect (m_ptBgLT.x (), m_ptBgRB.y (), m_ptBgRB.x ()-convert (), nHBg-m_ptBgRB.y (); // RBpainter. drawPixmap (QRect (ptDstRB. x (), ptDstRB. y (), nW-ptDstRB. x (), nH-ptDstRB. y (), srcPix, QRect (m_ptBgRB.x (), m_ptBgRB.y (), nWBg-m_ptBgRB.x (), nHBg-m_ptBgRB.y (); painter. end (); return dstPix;} BFWidget: BFWidget (QWidget * parent): QDialog (parent) {// load shadow _ pixShadow. loadFromData (_ hexData, 588); // _ pixShadow. load ("box-shadow.png"); this-> setWindowFlags (Qt: FramelessWindowHint); this-> setAttribute (Qt: WA_TranslucentBackground ); this-> resize (600 + 12,400 + 12); this-> setContentsMargins (6, 6, 6);} void BFWidget: mousePressEvent (QMouseEvent * event) {// only move the left mouse button and change the size if (event-> button () = Qt: LeftButton) {mouse_press = true ;} // window movement distance move_point = event-> globalPos ()-pos ();} void BFWidget: mouseReleaseEvent (QMouseEvent *) {mouse_press = false;} void BFWidget :: mouseMoveEvent (QMouseEvent * event) {// move the window if (mouse_press) {QPoint move_pos = event-> globalPos (); move (move_pos-move_point);} // void BFWidget:: resizeEvent (QResizeEvent * event) // {// QSize size = event-> size (); // container-> setGeometry (5, 5, size. width ()-10, size. height ()-10); // qDebug () <container-> rect (); //} void BFWidget: paintEvent (QPaintEvent * event) {QPainter painter (this); static QColor colItemBg (255,255,255); // Default background color QSize szThis = this-> rect (). size (); QPixmap pixShadowBg = _ DrawNinePatch (szThis, _ pixShadow); // pixShadowBg. save ("c:/pixShadowBg1.png"); painter. drawPixmap (this-> rect (), pixShadowBg); painter. setPen (colItemBg); // You need to draw a background. Otherwise, it will penetrate through painter. setBrush (colItemBg); painter. drawRect (6, 6, szThis. width ()-6*2, szThis. height ()-6*2); // this-> setMask (pixShadowBg. mask (); // sets the rounded corner}

# Ifndef BFWIDGET_H # define BFWIDGET_H # include <QWidget> # include <QDialog> # include <QMouseEvent> # include <QResizeEvent>/*** you can drag the * window to increase the shadow effect *@ brief The BFWidget class */class BFWidget: public QDialog {Q_OBJECTpublic: explicit BFWidget (QWidget * parent = 0); signals: public slots: protected: void mousePressEvent (QMouseEvent * event); void mouseReleaseEvent (QMouseEvent * event ); void mouseMoveEvent (QMouseEvent * event); // void resizeEvent (QResizeEvent * event); void paintEvent (QPaintEvent * event); private: // QPixmap _ pixShadow; // shadow image QPoint move_point; // The moving distance from bool mouse_press; // press the left mouse button}; # endif // BFWIDGET_H
 
 



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.