In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
QT full screen display child window
The method of displaying child windows full screen in QT the widget QWidget member function showFullScreen () in QT; is used to display the widget full screen but it is only useful for widgets in window mode. The characteristic of a child window is that Qt::SubWindow is not a separate window. Therefore, it is invalid to call showFullScreen on it. By calling setWindowFlags Qt on the child window:
After Dialog or setWindowFlagsQt::Window sets it to window mode, you can call showFullScreen () for full-screen display. Relative to the full-screen display method of the child window, we have to mention the method of exiting the full-screen of the child window. The method of exiting the full screen of the sub-window of MFC is simply to directly call the SetWindowPos function to display the child window to the predetermined position. There is no effect on window positioning by using move and resize directly in QT. You need to set the child window to non-window mode first. Then move the window to the desired location.
That is, first call setWindowFlags Qt::Dialog or setWindowFlags Qt::SubWindow before calling the move and resize functions. Someone mentioned calling showNormal and then calling setWindowFlags Qt::SubWindow when exiting full screen. There are two problems. 1showNormal is only valid for top-level windows. 2 you can consider calling showNormal to set the window to its original size before setting the window as a child window mode. However, when the window goes back to the parent window, it will not show its original size.
How QT maximizes the initial form
Today, I want to maximize the initial run of a form. I thought it was easy. A problem took about two hours to solve. It's a painful problem, but the solution is actually very simple. There's one in QT.
Void QWidget::setWindowState (Qt::WindowStateswindowState)
Through this function, you can set the initial state of the form. Qt::WindowStates has the following states
Constant Value Description The window has no state set (in normal state).
Qt::WindowNoState Qt::WindowMinimized
0x00000000 0x00000001
The window is minimized (i.e. Iconified).
Qt::WindowMaximized Qt::WindowFullScreen Qt::WindowActive
0x00000002 0x00000004 0x00000008
The window is maximized with a frame around it. The window fills the entire screen without any frame around it. The window is the active window, i.e. It has keyboard focus.
With this, it's very easy. All you need to maximize the form is
SetWindowState (Qt::WindowMaximized); that's fine.
Registering and using C++ objects in qml and minimizing forms in qml
The related codes in the main function are as follows: QApplication app (argc, argv); QDeclarativeView view; / / the operations such as view.rootContext ()-> setContextProperty ("WindowQuitControl", & app); view.rootContext ()-> setContextProperty ("WindowControl", & view) when registering app in qml minimizes the exit of the main program. At the same time, you need to import the header # include. Here, the app and QDeclarativeView objects are registered in QML. By referencing "WindowQuitControl" and "WindowControl", these two nouns will be used in the next qml file, just like using app and view in C++. Here the view can be QDeclarativeView or QmlApplicationViewer. If the QtQuick application automatically generated by the system is the latter object, the previous one is used because the code has special requirements.
1. The reason for registering app in qml is that QDeclarativeView does not have a quit () method, so if you use Qt.quit () in qml, it will prompt signal quit that there is no recipient. One of my solutions is to register app in qml by using / / * *. Qml in qml. MouseArea {onClicked: WindowQuitControl.quit ();}. This allows you to exit the program as well. If you want to do something before exiting the program, you can register the relevant class in qml, then write the relevant operation in the corresponding quit-like method, and then call it in qml. Ps: if the view declared here is that QmlApplicationViewer view; uses Qt.quit () in qml, there will be no problem of saying that the quit method does not have a receiver and then cannot exit.
2, the question about the maximum and minimum of the form if you want to achieve maximum or minimum after a button click in qml, you can register view into qml as above and then call onClicked: WindowControl.showFullScreen (); onClicked: WindowControl.showMinimized () in qml to minimize full-screen display. And through the following sentence
WindowControl.lower ()
You can put the form at the bottom instead of minimizing it. But if you write it into a mobile app, you can minimize the effect, similar to running in the background.
Add that the call to the above function is due to the special need that when the implemented application does not have a frame, it must achieve the maximum and minimum effect on its own. If you use windows's own interface border style mouse click or screen touch, you can achieve maximum minimization. 3, after going to the border how to go to the border to refer to my previous blog, simply calling showMaximized and other methods has no effect. This is because the change size mode in view is set to SizeViewToRootObject by default. You need to modify the ResizeMode yourself. The code snippet is as follows / / set the mode Mode to resize qml default QDeclarativeView::SizeViewToRootObject view.setResizeMode (QDeclarativeView::SizeRootObjectToView); view.showMaximized (); if view is QmlApplicationViewer, then the parameter is QmlApplicationViewer::SizeRootObjectToView
The functions related to form maximum minimization and window size modification in Qt use 2.
In the previous article, it was mentioned that some show, showNormal, showMaximized and other methods of view are called to achieve normal window display. But later, in the process of implementation, I found that the maximization of the window and the full screen are the same effect, which is completely not in line with my original wishes, ah, especially the functions that can be used by these show methods that call view in qml are even less inconvenient. Finally, after a day of experiment, there is finally a solution.
The functions used are
View- > showNormal ()
View- > showMinimized ()
View- > showFullScreen (); view- > showMaximized (). 1. In order to set the length, width and coordinate position of the form, you need to use these functions QApplication::desktop ()-> width () QApplication::desktop ()-> height (). These two functions can obtain the length and width of the current desktop, that is, the length and width of the maximum resolution need to be imported into the file # include # include.
2. The length and width here is the width that includes, for example, the status bar at the bottom of windows. In order to obtain the effective width of the desktop, you can use this method QApplication::desktop ()-> availableGeometry (). Width () QApplication::desktop ()-> availableGeometry (). Height () this method will get the length and width of the removal status bar.
3. Set the display coordinates of view view- > setGeometry (0J0, QApplication::desktop ()-> availableGeometry (). Width (), QApplication::desktop ()-> availableGeometry (). Height ()). Here the setting coordinate parameters are the first two x and y coordinates of the form.
The last two are view- > setMaximumHeight (maxh); view- > setMaximumWidth (maxw); these two can also be used to set the maximum length and width and then give the maximum and minimum length of the form. But with this function, you can't call a method like showNormal to make it appear as a small form. The special case of these methods discussed in this article is that if there is no border in the application form, if you do not have these problems with qt, then what to do when you encounter this situation? instead of using showNormal, you will use setGeometry. Remember to use pressedEvent and moveEvent to record mouse movements. 4. Resize function resize (w) Qt the function that displays a fixed size sets the form to the specified length and width
To sum up, the combination of these methods will be able to solve most of the window requirements. Haha, if you can't, there are still a lot of untried ways to learn qt.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.