QT 5 Little practice Create borderless interface

Source: Internet
Author: User

We all know that the interface of QT5 is not so beautiful, and every software we find their borders are custom, so I decided to write a blog post, perhaps there are many articles written by Daniel, but I still want to write a record of their own learning QT course

First, we have to write the borderless code in the corresponding constructor (for example, the blogger wants Mywidget to become borderless)

Setwindowflags (Qt::framelesswindowhint | Qt::windowstaysontophint);

Set the border state, after no border, you must write a mouse event to drag it

Setmousetracking (TRUE); Turn on mouse tracking events

We're going to have three functions, press,release, and move, and a bool press; Determine if the mouse is pressed, as well as the Qpoint Start_pos; record the starting position, Qpoint End_pos, record the end position, and their difference is how far we want to move. For example, the starting position is (0,0) the end position is (200,300), then our borderless interface moves (200,300) units. The most important thing to do is to initialize the Press=flase, because you didn't press the mouse at first.


void Mywidget::mousepressevent (Qmouseevent *e)
{
Press = TRUE;
Start_pos=e->pos ();
}
void Mywidget::mousemoveevent (Qmouseevent *e)
{
if (press)
{
Qpoint End_pos = E->globalpos ();
In the process of moving, the coordinates are changing, only when the mouse is released, the press becomes false, coordinates are determined, the window starts to move
This->move (End_pos-start_pos);
}
}
void Mywidget::mousereleaseevent (Qmouseevent *)
{
Press=false; Used to end the coordinate changes in the mousemoveevent and to determine the end coordinates
}

References from Baidu. Belong to Bo Master Original, reproduced please indicate the source

QT 5 Little practice Create borderless interface

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.