Toplevel WidgetsThis example demonstrates the use of Qt's widget flags to provide toplevel widgets with customized window decorations. It provides a graphical user interface for selecting different options for widget decoration and behavior, and passes the appropriate widget flags to the QWidget constructor. QWidget::reparent() is used to change the widget flags at runtime. Warning: Note that the interpretation and functionality of the widget flags depends on the window manager used when running the application. Many window managers do not support every possible flag combination. The user interface providing the different options was created using Qt Designer. The different options are explained in the user interface through the use of tooltips and What's This help. Load the options.ui file into Qt Designer for more details.
#include <qapplication.h> #include "options.h" int main( int argc, char ** argv ) { QApplication a( argc, argv ); OptionsDialog dlg; return dlg.exec(); } The main function creates and displays the dialog for the user interface. Note that this dialog is modal. The code relevant for this example is in the options.ui.h file.
void OptionsDialog::apply() { WFlags f = WDestructiveClose | WType_TopLevel | WStyle_Customize; The apply() slot declares the widget flag variable f and initializes it with the values
if ( bgBorder->isChecked() ) { if ( rbBorderNormal->isChecked() ) f |= WStyle_NormalBorder; else if ( rbBorderDialog->isChecked() ) f |= WStyle_DialogBorder;The window gets a normal or dialog border depending on the selected option.
if ( bgTitle->isChecked() ) { f |= WStyle_Title; if ( cbTitleSystem->isChecked() ) f |= WStyle_SysMenu; if ( cbTitleMinimize->isChecked() ) f |= WStyle_Minimize; if ( cbTitleMaximize->isChecked() ) f |= WStyle_Maximize; if ( cbTitleContext->isChecked() ) f |= WStyle_ContextHelp; }A titlebar with controls is provided if the appropriate options have been checked.
} else { f |= WStyle_NoBorder; }If the window should not have a border it cannot have a titlebar. Widgets that provide their own (e.g. themed) window decoration should use this flag.
QWidget *parent = this; if ( cbBehaviorTaskbar->isChecked() ) { parent = 0; f |= WGroupLeader; }If a toplevel widget has a parent it will not have a taskbar entry, and on most window managers it will always stay on top of the parent widget. This is the standard behavior for dialog boxes, especially if they are modeless, and for other secondary toplevel widgets. To provide a taskbar entry the widget must have no parent, in which case we need to use the WGroupLeader flag to prevent blocking through the modal main dialog. Applications that can have multiple toplevel windows open simultaneously should use this combination.
if ( cbBehaviorStays->isChecked() ) f |= WStyle_StaysOnTop /*| WX11BypassWM*/;A toplevel widget can stay on top of the whole desktop if the window manager supports this functionality. (1) Widgets that display important or realtime information (i.e. IRC clients) might benefit from using that flag.
if ( cbBehaviorPopup->isChecked() ) f |= WType_Popup;A popup widget is a short lived modal widget that closes automatically. Popup menus are a typical example for such widgets.
if ( cbBehaviorModal->isChecked() ) f |= WShowModal;A modal widget blocks input to other toplevel widgets, unless those are in a different modal group (see WGroupLeader). Dialogs are often modal, and the QDialog class provides an easy API to create and display them without the need to explicitly use this flag.
if ( cbBehaviorTool->isChecked() ) f |= WStyle_Tool;A tool window will never have a task bar entry (even if it has no parent widget), and often has a smaller window decoration. Tool windows are frequently used instead of modeless dialogs.
if ( !widget ) { widget = new QVBox( parent, 0, f );The widget is created if it has not been created yet, or if it was closed (since we use the WDestructiveClose flag). (2)
} else {If the widget has already been created the reparent() function is used to modify the widget's flags. The widget's geometry is not changed, and the widget is shown again immediately.
Finally the higher level properties such as the window's caption and icon are set. To build the example go to the toplevel directory
(QTDIR/examples/toplevel)
(3) See also Examples.
|
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le Qt Labs au hasardLe moteur de rendu OpenGLLes Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.2 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com