Remove the title bar of the window and move the window after removing the title bar.

Source: Internet
Author: User

Recently, the company is working on a C ++ project, and its functions are almost done. Now it is an interface modification. To make a good-looking interface, the title bar is a problem. So I chose to remove the title bar, the method to remove the title bar is relatively simple, just a line of code this-> setWindowFlags (Qt: FramelessWindowHint); after removing it, another problem is that the window cannot be moved, so I overwrote three mouse events. The Code is as follows. code of the hfile: # include <QMouseEvent> protected: void mousePressEvent (QMouseEvent * e); void mouseMoveEvent (QMouseEvent * e); void mouseReleaseEvent (QMouseEvent * e ); http://www.bcwhy.com/thread-17852-1-1.htmlprivate: QPoint last ;. cpp file code // you can In the constructor, the last variable uses its member function setX and setY. // The next step is to overwrite the three mouse events void MainWindow: mousePressEvent (QMouseEvent * e) {last = e-> globalPos ();} void MainWindow: mouseMoveEvent (QMouseEvent * e) {www.2cto.com int dx = e-> globalX ()-last. x (); int dy = e-> globalY ()-last. y (); last = e-> globalPos (); move (x () + dx, y () + dy);} void MainWindow: mouseReleaseEvent (QMouseEvent * e) {int dx = e-> globalX ()-last. x (); int dy = e-> glo BalY ()-last. y (); move (x () + dx, y () + dy);} remember to change the Class Name When copying it ~ In this way, you can drag the form after removing the title bar of the window.

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.