Case study of QT personalized forms without borders, transparency, mobility, and

Source: Internet
Author: User
Document directory
  • Add it to your resource package and set it as the background of the form.
  •  

Many of my friends asked me how to do the transparent effect. Why do my borderless forms cannot be moved? I am tired of answering them one by one. I just wrote them and shared them.

 int main(int argc, char *argv[]){    QApplication::setStyle("cleanlooks");    QApplication a(argc, argv);    login w;    w.setWindowTitle("ClientLogin");    w.setWindowOpacity(1);    w.setWindowFlags(Qt::FramelessWindowHint);    w.setAttribute(Qt::WA_TranslucentBackground);    w.show();    w.move(200,100);    return a.exec();}


The key statement is:

w.setWindowOpacity(1);    w.setWindowFlags(Qt::FramelessWindowHint);    w.setAttribute(Qt::WA_TranslucentBackground);

If you do not know what these statements mean, Press F1 or directly view the help documentation ......

The settings for the form without borders should be written in the main, so that all derived subwindows, qdialog, and qwidget can be inherited, well planned and managed to facilitate unified beautification design.

Take a chat window in the project as an example. First, use psto create a background image of the Form. Note that it is stored in PNG format, which is the key to transparency. No ps. You can find some PNG resource images. My PNG transparent background image is:

 

 

Add it to your resource package and set it as the background of the form. It's my project, and the scenario settings are actually the background image of the new project ~~

You can preview the transparent borderless form, but there is another important problem that the window cannot be moved.
This is also caused by no borders ...... I will not elaborate on the specific reasons. It is very clear to search for them. I will only talk about the solution.
In each subwindow, add:

void yourwindow::mousePressEvent(QMouseEvent *event){                                                                                                                this->windowPos = this->pos();         this->mousePos = event->globalPos();        this->dPos = mousePos - windowPos;}void yourwindow::mouseMoveEvent(QMouseEvent *event){         this->move(event->globalPos() - this->dPos);}
In this way, the success is achieved. Run it to see the effect. The green forest is a desktop, which can be ignored. Welcome

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.