QT changes a form to a top-level form

Source: Internet
Author: User

We know that with the mouse double-click an application icon on Windows, the application tends to appear in front of us as a top-level window, but how do we activate it as a top-level window for a non-top-level window that has already been opened?

To achieve activation, this must meet two conditions, first, must have notification activation of the person, this person must be another application (or a different example of the same application), he can send information to the form; second, the form can parse out the message. There are many ways that an application can send messages to another application, such as shared memory, the way the network is, and so on. Here is no detail, good, gossip less, we get to the point, with the previous two conditions, assuming that the form's application now resolves to another application's notification activation message, then how the form will be activated as the desktop of the top-level form it?

[CPP]View PlainCopy 
  1. void Cwidget::activatewindow ()
  2. {
  3. Qt::windowstates winstatus = qt::windownostate;
  4. if (WindowState () & qt::windowmaximized)
  5. {
  6. Winstatus = qt::windowmaximized;
  7. }
  8. Setwindowstate (qt::windowminimized);
  9. Setwindowstate (qt::windowactive | winstatus);
  10. Setgeometry (Curgemrect);
  11. Activatewindow ();
  12. Raise ();
  13. }

By calling the function in the form handler, you can make the form a top-level form, where CWidget is derived from qwidget (and of course other forms, as long as the final parent class of the form is Qwidget), and Curgemrect is a member variable of CWidget. Use to save the geometry of the form, so that you can remember where the form was last popped, but also reload two functions, resizeevent and moveevent, to keep the size and position of the form in mind when it changes.

[CPP]View PlainCopy 
    1. Voidcwidget::resizeevent (qresizeevent*event)
    2. {
    3. Curgemrect = Geometry ();
    4. }
    5. void Cwidget::moveevent (Qmoveevent *event)
    6. {
    7. Curgemrect = Geometry ();
    8. }
http://blog.csdn.net/rabinsong/article/details/8660783

QT changes a form to a top-level form

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.