Qt-netease Cloud music scene realization-1 window hidden drag move, custom title bar

Source: Internet
Author: User
<span id="Label3"></p><p><p>Recently also changed the company, also changed the new job, the salary also symbolically rose a little, but recently the heart still is laughed, do not know why, do not have that kind of sureness feeling, feel oneself can be abandoned at any time feeling. Feel oneself in wasted time, also feel oneself is wasting life.</p></p><p><p>To be able to have a job as a breadwinner when you are abandoned, you have to deepen your skills now. Give yourself a small goal, the first NetEase cloud music interface to achieve, in fact, this is my very good wishes, but I do not bother to move, has been dragged to the Present.</p></p><p><p>Put a reference on first</p></p><p><p></p></p><p><p>We take this as the main, first to achieve the main interface, here because there is no ready-made material, I also do not bother to find similar materials, i show my PS slag technology, the whole process of resource cutout Implementation.</p></p><p><p>Now after a Morning's efforts, finally made something, look first</p></p><p><p></p></p><p><p>Through the software discovery, NetEase Cloud Music interface realizes also hides the native window title bar, therefore, i in the same vein.</p></p><p><p>Currently implements the window to hide the interface port can be dragged and moved</p></p><p><p></p></p><p><p>The main use of QT qmouseevent inside the</p></p><pre class="brush:cpp;gutter:true;"><pre class="brush:cpp;gutter:true;">Mouse down void mousepressevent (qmouseevent* event)//mouse move void mousemoveevent (qmouseevent* event);//mouse release void Mousereleaseevent (qmouseevent* event);</pre></pre><p><p>  </p></p><p><p>To make the window move and drag</p></p><p><p>The implementation code is as follows</p></p><pre class="brush:cpp;gutter:true;"><pre class="brush:cpp;gutter:true;">/* * Mouse down action * Record current coordinates */static Qpoint last (0,0); Save coordinates const INT Title_height =; You can also use the macro definition to save the caption height, which is the height of the mouse click area void mainwindow::mousepressevent (qmouseevent *event) { if (event->y () < Title_height) {last = Event->globalpos (); }} /* Mouse Move function * Here to modify the Window's coordinates in real time */void mainwindow::mousemoveevent (qmouseevent *event) { if (event->y () <title_height ) { int dx = event->globalx ()-last.x (); int dy = event->globaly ()-last.y (); last = Event->globalpos (); This->move (this->x () +dx,this->y () +dy);} } /* Mouse release function */void mainwindow::mousereleaseevent (qmouseevent *event) { if (event->y () <title_height) { int dx = event->globalx ()-last.x (); int dy = event->globaly ()-last.y (); This->move (this->x () +dx,this->y () +dy);} }</pre></pre><p><p>  </p></p><p><p></p></p><p><p>With regard to the implementation of the background, there are small partners who may find that setting the bottom of the background is problematic, and I generally use two different ways</p></p><p><p>1. Just put a qlabel, as a background.</p></p><p><p>2. Draw the background using the Draw function</p></p><p><p>In this version, I used the second way, the code is as follows</p></p><pre class="brush:cpp;gutter:true;"><pre class="brush:cpp;gutter:true;">/* Draw function * Draw program Beijing */void MainWindow::p aintevent (qpaintevent *event) { q_unused (event); Qpainter Painter_mainback (this); Painter_mainback.drawpixmap (0,0,this->width (), this->height (), qpixmap (":/mianwindow/images/mainback.png") ); }</pre></pre><p><p> </p></p><p><p>Because I used the absolute layout in this version, the Maximize button I only did the slot function, but no actual function.</p></p><p><p></p></p><p><p>The logo on the top left is also the key to achieve, use Qlabel to put a resource just Fine.</p></p><p><p>In addition, my hair part of the resources will rely on QSS to connect, the following attached QSS content</p></p><pre class="brush:css;gutter:true;">/* title background file */qlabel#label_title_back{border-image:url (./images/title_back.png);} /* Close button */qpushbutton#pushbutton_close{border-image:url (images/btn_close_n.png);} Qpushbutton::hover#pushbutton_close{border-image:url (images/btn_close_h.png);} Qpushbutton::p Ressed#pushbutton_close{border-image:url (images/btn_close_n.png);} /* Maximize button */qpushbutton#pushbutton_max{border-image:url (images/btn_max_n.png);} Qpushbutton::hover#pushbutton_max{border-image:url (images/btn_max_h.png);} Qpushbutton::p Ressed#pushbutton_max{border-image:url (images/btn_max_n.png);} /* Minimize button */qpushbutton#pushbutton_min{border-image:url (images/btn_min_n.png);} Qpushbutton::hover#pushbutton_min{border-image:url (images/btn_min_h.png);} Qpushbutton::p Ressed#pushbutton_min{border-image:url (images/btn_min_n.png);} /* Mini button */qpushbutton#pushbutton_mini{border-image:url (images/btn_mini_n.png);} Qpushbutton::hover#pushbutton_mini{border-image:url (images/btn_mini_h.png);} Qpushbutton::p Ressed#pushbutton_mini{border-image:url (images/btn_mini_n.png);} /* MarkTitle logo file */qlabel#label_title_logo{border-image:url (./images/title_logo.png);} </pre><p><p>well, this morning on the realization of these features, I hope to help small partners, you can add me to exchange, see</p></p><p><p></p></p><p><p> </p></p><p><p>Qt-netease Cloud music scene realization-1 window hidden drag move, custom title bar</p></p></span>

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.