QT implements a shadow form similar to QQ

Source: Internet
Author: User

#ifndef bfwidget_h#define bfwidget_h#include <QWidget> #include <QMouseEvent> #include <qresizeevent >/** * Window can drag * window to add shadow effect * @brief the Bfwidget class */class bfwidget:public qwidget{    q_objectpublic:    explici T Bfwidget (Qwidget *parent = 0);    /**     * Rewrite spatial typesetting settings     * Place the space on the central_widget     * @brief setlayout     * @param layout     *    /void setlayout ( Qlayout * layout); Signals:public slots:protected:    void Mousepressevent (Qmouseevent *event);    void Mousereleaseevent (Qmouseevent *event);    void Mousemoveevent (Qmouseevent *event);    void Resizeevent (qresizeevent *event);p rivate:    //area to display content    qwidget     *central_widget;    Qpoint Move_point; Move the distance    bool mouse_press;//Press left mouse button}; #endif//Bfwidget_h

<pre name= "code" class= "CPP" > #include <QBoxLayout> #include <QPalette> #include < qgraphicsdropshadoweffect> #include <QDebug> #include <QSizePolicy> #include "bfwidget.h" Bfwidget::    Bfwidget (Qwidget *parent): Qwidget (parent) {setwindowflags (qt::framelesswindowhint);    SetAttribute (Qt::wa_translucentbackground);    Central_widget = new Qwidget (); Central_widget->setsizepolicy (qsizepolicy::expanding,qsizepolicy::expanding);    Horizontal and vertical directions arbitrarily stretched qpalette palette;    Palette.setbrush (Qpalette::background,qbrush (Qcolor (255,255,255)));    Central_widget->setpalette (palette);    Central_widget->setautofillbackground (TRUE);    Qgraphicsdropshadoweffect *shadow_effect = new Qgraphicsdropshadoweffect ();    Shadow_effect->setblurradius (10.0);    Shadow_effect->setcolor (qcolor (0, 0, 0, 100));    Shadow_effect->setoffset (1.0);    Central_widget->setgraphicseffect (Shadow_effect);    Qvboxlayout * main_layout = new qvboxlayout (); Main_laYout->addwidget (Central_widget, Qt::aligncenter);    Main_layout->addspacing (0);    Main_layout->setcontentsmargins (5,5,5,5); Qwidget::setlayout (main_layout);} void Bfwidget::setlayout (Qlayout *layout) {central_widget->setlayout (layout);}    void Bfwidget::mousepressevent (Qmouseevent * Event) {//can only be left mouse button move and change size if (event->button () = = Qt::leftbutton)    {mouse_press = true; }//window move Distance move_point = Event->globalpos ()-POS ();} void Bfwidget::mousereleaseevent (Qmouseevent *) {mouse_press = false;} void Bfwidget::mousemoveevent (Qmouseevent *event) {//Move window if (mouse_press) {Qpoint Move_pos = Event->gl        Obalpos ();    Move (Move_pos-move_point); }}//void bfwidget::resizeevent (qresizeevent *event)//{//qsize size = Event->size ();//Central_widget->setgeom Etry (5, 5, Size.width ()-Ten, Size.Height ()-ten);//Qdebug () << central_widget->rect ();/}


QT implements a shadow form similar to QQ

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.