Main ideas:
1: Set the form to QT: frameless=whint (remove the title bar ).
2: Use a transparent image in some areas as the program interface, and set the transparency of the image as penetration.
3: The mouse event of the reload program.
Runtime (the desktop background is light green)
Source code:
# Include <qtgui> class irregularwidget: Public qwidget {q_object public: irregularwidget (qwidget * parent = 0); protected: void mousepressevent (qmouseevent * event ); void mousemoveevent (qmouseevent * event); void paintevent (qpaintevent * event); void enterevent (qevent * event); void leaveevent (qevent * event); Private: qpoint m_currentpos; qpixmap m_pixmap;}; irregularwidget: irregularwidget (qwidget * parent): qwidget (parent, QT: framelesswindowhint) {setwindowtitle ("irregular widget "); // load a transparent image in some areas as the program interface m_pixmap.load ("delete.png"); resize (m_pixmap.size (); // key to irregular windows, set the transparent part of the image to penetrate setmask (m_pixmap.mask ();} void irregularwidget: mousepressevent (qmouseevent * event) {// press and hold the left button to hold the window, right-click to close the program if (Event-> button () = QT: leftbutton) {m_currentpos = event-> globalpos ()-framegeometry (). topleft (); event-> Accept ();} else if (Event-> button () = QT: rightbutton) Close ();} void irregularwidget :: mousemoveevent (qmouseevent * event) {If (Event-> buttons () & QT: leftbutton) {move (Event-> globalpos ()-m_currentpos ); event-> Accept () ;}} void irregularwidget: paintevent (qpaintevent * event) {qpainter painter (this); painter. drawpixmap (0, 0, m_pixmap);} void irregularwidget: leaveevent (qevent * event) {// when the mouse leaves the window, it is a common pointer setcursor (QT: arrowcursor );} void irregularwidget: enterevent (qevent * event) {// when the mouse stays on the window, it is a finger setcursor (QT: pointinghandcursor);} # include "Main. MOC "int main (INT argc, char * argv []) {qapplication app (argc, argv); irregularwidget * widget = new irregularwidget; widget-> show (); return app.exe C ();}