<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>dialog.cpp Example File | Qt Widgets 5.11</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-dialogs-standarddialogs-example.html">Standard Dialogs Example</a></td><td >dialog.cpp Example File</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">dialog.cpp Example File</h1> <span class="subtitle">dialogs/standarddialogs/dialog.cpp</span> <!-- $$$dialogs/standarddialogs/dialog.cpp-description --> <div class="descr"> <a name="details"></a> <pre class="cpp"> <span class="comment">/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/</span> <span class="preprocessor">#include <QtWidgets></span> <span class="preprocessor">#include "dialog.h"</span> <span class="preprocessor">#define MESSAGE \ Dialog::tr("<p>Message boxes have a caption, a text, " \ "and any number of buttons, each with standard or custom texts." \ "<p>Click a button to close the message box. Pressing the Esc button " \ "will activate the detected escape button (if any).")</span> <span class="preprocessor">#define MESSAGE_DETAILS \ Dialog::tr("If a message box has detailed text, the user can reveal it " \ "by pressing the Show Details... button.")</span> <span class="keyword">class</span> DialogOptionsWidget : <span class="keyword">public</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> { <span class="keyword">public</span>: <span class="keyword">explicit</span> DialogOptionsWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>); <span class="type">void</span> addCheckBox(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&</span>text<span class="operator">,</span> <span class="type">int</span> value); <span class="type">void</span> addSpacer(); <span class="type">int</span> value() <span class="keyword">const</span>; <span class="keyword">private</span>: <span class="keyword">typedef</span> <span class="type"><a href="../qtcore/qpair.html">QPair</a></span><span class="operator"><</span><span class="type"><a href="qcheckbox.html">QCheckBox</a></span> <span class="operator">*</span><span class="operator">,</span> <span class="type">int</span><span class="operator">></span> CheckBoxEntry; <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout; <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator"><</span>CheckBoxEntry<span class="operator">></span> checkBoxEntries; }; DialogOptionsWidget<span class="operator">::</span>DialogOptionsWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent) : <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(parent) <span class="operator">,</span> layout(<span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>) { setTitle(Dialog<span class="operator">::</span>tr(<span class="string">"Options"</span>)); setLayout(layout); } <span class="type">void</span> DialogOptionsWidget<span class="operator">::</span>addCheckBox(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&</span>text<span class="operator">,</span> <span class="type">int</span> value) { <span class="type"><a href="qcheckbox.html">QCheckBox</a></span> <span class="operator">*</span>checkBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcheckbox.html">QCheckBox</a></span>(text); layout<span class="operator">-</span><span class="operator">></span>addWidget(checkBox); checkBoxEntries<span class="operator">.</span>append(CheckBoxEntry(checkBox<span class="operator">,</span> value)); } <span class="type">void</span> DialogOptionsWidget<span class="operator">::</span>addSpacer() { layout<span class="operator">-</span><span class="operator">></span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding)); } <span class="type">int</span> DialogOptionsWidget<span class="operator">::</span>value() <span class="keyword">const</span> { <span class="type">int</span> result <span class="operator">=</span> <span class="number">0</span>; foreach (<span class="keyword">const</span> CheckBoxEntry <span class="operator">&</span>checkboxEntry<span class="operator">,</span> checkBoxEntries) <span class="keyword">if</span> (checkboxEntry<span class="operator">.</span>first<span class="operator">-</span><span class="operator">></span>isChecked()) result <span class="operator">|</span><span class="operator">=</span> checkboxEntry<span class="operator">.</span>second; <span class="keyword">return</span> result; } Dialog<span class="operator">::</span>Dialog(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent) : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent) { <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>verticalLayout; <span class="keyword">if</span> (<span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>styleHints()<span class="operator">-</span><span class="operator">></span>showIsFullScreen() <span class="operator">|</span><span class="operator">|</span> <span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>styleHints()<span class="operator">-</span><span class="operator">></span>showIsMaximized()) { <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>horizontalLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>(<span class="keyword">this</span>); <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>groupBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(<span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>applicationDisplayName()<span class="operator">,</span> <span class="keyword">this</span>); horizontalLayout<span class="operator">-</span><span class="operator">></span>addWidget(groupBox); verticalLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(groupBox); } <span class="keyword">else</span> { verticalLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(<span class="keyword">this</span>); } <span class="type"><a href="qtoolbox.html">QToolBox</a></span> <span class="operator">*</span>toolbox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbox.html">QToolBox</a></span>; verticalLayout<span class="operator">-</span><span class="operator">></span>addWidget(toolbox); errorMessageDialog <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qerrormessage.html">QErrorMessage</a></span>(<span class="keyword">this</span>); <span class="type">int</span> frameStyle <span class="operator">=</span> <span class="type"><a href="qframe.html">QFrame</a></span><span class="operator">::</span>Sunken <span class="operator">|</span> <span class="type"><a href="qframe.html">QFrame</a></span><span class="operator">::</span>Panel; integerLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; integerLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>integerButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QInputDialog::get&Int()"</span>)); doubleLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; doubleLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>doubleButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QInputDialog::get&Double()"</span>)); itemLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; itemLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>itemButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QInputDialog::getIte&m()"</span>)); textLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; textLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>textButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QInputDialog::get&Text()"</span>)); multiLineTextLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; multiLineTextLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>multiLineTextButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QInputDialog::get&MultiLineText()"</span>)); colorLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; colorLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>colorButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QColorDialog::get&Color()"</span>)); fontLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; fontLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>fontButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QFontDialog::get&Font()"</span>)); directoryLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; directoryLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>directoryButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QFileDialog::getE&xistingDirectory()"</span>)); openFileNameLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; openFileNameLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>openFileNameButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QFileDialog::get&OpenFileName()"</span>)); openFileNamesLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; openFileNamesLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>openFileNamesButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QFileDialog::&getOpenFileNames()"</span>)); saveFileNameLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; saveFileNameLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>saveFileNameButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QFileDialog::get&SaveFileName()"</span>)); criticalLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; criticalLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>criticalButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QMessageBox::critica&l()"</span>)); informationLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; informationLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>informationButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QMessageBox::i&nformation()"</span>)); questionLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; questionLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>questionButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QMessageBox::&question()"</span>)); warningLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; warningLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>warningButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QMessageBox::&warning()"</span>)); errorLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>; errorLabel<span class="operator">-</span><span class="operator">></span>setFrameStyle(frameStyle); <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>errorButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(tr(<span class="string">"QErrorMessage::showM&essage()"</span>)); connect(integerButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setInteger); connect(doubleButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setDouble); connect(itemButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setItem); connect(textButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setText); connect(multiLineTextButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setMultiLineText); connect(colorButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setColor); connect(fontButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setFont); connect(directoryButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setExistingDirectory); connect(openFileNameButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setOpenFileName); connect(openFileNamesButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setOpenFileNames); connect(saveFileNameButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>setSaveFileName); connect(criticalButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>criticalMessage); connect(informationButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>informationMessage); connect(questionButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>questionMessage); connect(warningButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>warningMessage); connect(errorButton<span class="operator">,</span> <span class="operator">&</span><span class="type"><a href="qabstractbutton.html">QAbstractButton</a></span><span class="operator">::</span>clicked<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="operator">&</span>Dialog<span class="operator">::</span>errorMessage); <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>page <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>; <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(page); layout<span class="operator">-</span><span class="operator">></span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>setColumnMinimumWidth(<span class="number">1</span><span class="operator">,</span> <span class="number">250</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(integerButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(integerLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(doubleButton<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(doubleLabel<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(itemButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(itemLabel<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(textButton<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(textLabel<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(multiLineTextButton<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(multiLineTextLabel<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding)<span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="number">0</span>); toolbox<span class="operator">-</span><span class="operator">></span>addItem(page<span class="operator">,</span> tr(<span class="string">"Input Dialogs"</span>)); <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> doNotUseNativeDialog <span class="operator">=</span> tr(<span class="string">"Do not use native dialog"</span>); page <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>; layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(page); layout<span class="operator">-</span><span class="operator">></span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(colorButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(colorLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>); colorDialogOptionsWidget <span class="operator">=</span> <span class="keyword">new</span> DialogOptionsWidget; colorDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(doNotUseNativeDialog<span class="operator">,</span> <span class="type"><a href="qcolordialog.html">QColorDialog</a></span><span class="operator">::</span>DontUseNativeDialog); colorDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Show alpha channel"</span>) <span class="operator">,</span> <span class="type"><a href="qcolordialog.html">QColorDialog</a></span><span class="operator">::</span>ShowAlphaChannel); colorDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"No buttons"</span>) <span class="operator">,</span> <span class="type"><a href="qcolordialog.html">QColorDialog</a></span><span class="operator">::</span>NoButtons); layout<span class="operator">-</span><span class="operator">></span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding)<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(colorDialogOptionsWidget<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span> <span class="operator">,</span><span class="number">2</span>); toolbox<span class="operator">-</span><span class="operator">></span>addItem(page<span class="operator">,</span> tr(<span class="string">"Color Dialog"</span>)); page <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>; layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(page); layout<span class="operator">-</span><span class="operator">></span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(fontButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(fontLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>); fontDialogOptionsWidget <span class="operator">=</span> <span class="keyword">new</span> DialogOptionsWidget; fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(doNotUseNativeDialog<span class="operator">,</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>DontUseNativeDialog); fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Show scalable fonts"</span>)<span class="operator">,</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>ScalableFonts); fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Show non scalable fonts"</span>)<span class="operator">,</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>NonScalableFonts); fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Show monospaced fonts"</span>)<span class="operator">,</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>MonospacedFonts); fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Show proportional fonts"</span>)<span class="operator">,</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>ProportionalFonts); fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"No buttons"</span>) <span class="operator">,</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>NoButtons); layout<span class="operator">-</span><span class="operator">></span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding)<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(fontDialogOptionsWidget<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span> <span class="operator">,</span><span class="number">2</span>); toolbox<span class="operator">-</span><span class="operator">></span>addItem(page<span class="operator">,</span> tr(<span class="string">"Font Dialog"</span>)); page <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>; layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(page); layout<span class="operator">-</span><span class="operator">></span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(directoryButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(directoryLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(openFileNameButton<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(openFileNameLabel<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(openFileNamesButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(openFileNamesLabel<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(saveFileNameButton<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(saveFileNameLabel<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">1</span>); fileDialogOptionsWidget <span class="operator">=</span> <span class="keyword">new</span> DialogOptionsWidget; fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(doNotUseNativeDialog<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontUseNativeDialog); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Show directories only"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>ShowDirsOnly); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Do not resolve symlinks"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontResolveSymlinks); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Do not confirm overwrite"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontConfirmOverwrite); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Do not use sheet"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontUseSheet); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Readonly"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>ReadOnly); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Hide name filter details"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>HideNameFilterDetails); fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>addCheckBox(tr(<span class="string">"Do not use custom directory icons (Windows)"</span>)<span class="operator">,</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontUseCustomDirectoryIcons); layout<span class="operator">-</span><span class="operator">></span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding)<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(fileDialogOptionsWidget<span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span> <span class="operator">,</span><span class="number">2</span>); toolbox<span class="operator">-</span><span class="operator">></span>addItem(page<span class="operator">,</span> tr(<span class="string">"File Dialogs"</span>)); page <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>; layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(page); layout<span class="operator">-</span><span class="operator">></span>setColumnStretch(<span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(criticalButton<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(criticalLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(informationButton<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(informationLabel<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(questionButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(questionLabel<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(warningButton<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(warningLabel<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(errorButton<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">></span>addWidget(errorLabel<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">1</span>); layout<span class="operator">-</span><span class="operator">></span>addItem(<span class="keyword">new</span> <span class="type"><a href="qspaceritem.html">QSpacerItem</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Ignored<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>MinimumExpanding)<span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="number">0</span>); toolbox<span class="operator">-</span><span class="operator">></span>addItem(page<span class="operator">,</span> tr(<span class="string">"Message Boxes"</span>)); setWindowTitle(<span class="type"><a href="../qtgui/qguiapplication.html">QGuiApplication</a></span><span class="operator">::</span>applicationDisplayName()); } <span class="type">void</span> Dialog<span class="operator">::</span>setInteger() { bool ok; <span class="type">int</span> i <span class="operator">=</span> <span class="type"><a href="qinputdialog.html">QInputDialog</a></span><span class="operator">::</span>getInt(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QInputDialog::getInteger()"</span>)<span class="operator">,</span> tr(<span class="string">"Percentage:"</span>)<span class="operator">,</span> <span class="number">25</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">100</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="operator">&</span>ok); <span class="keyword">if</span> (ok) integerLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"%1%"</span>)<span class="operator">.</span>arg(i)); } <span class="type">void</span> Dialog<span class="operator">::</span>setDouble() { bool ok; <span class="type">double</span> d <span class="operator">=</span> <span class="type"><a href="qinputdialog.html">QInputDialog</a></span><span class="operator">::</span>getDouble(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QInputDialog::getDouble()"</span>)<span class="operator">,</span> tr(<span class="string">"Amount:"</span>)<span class="operator">,</span> <span class="number">37.56</span><span class="operator">,</span> <span class="operator">-</span><span class="number">10000</span><span class="operator">,</span> <span class="number">10000</span><span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="operator">&</span>ok); <span class="keyword">if</span> (ok) doubleLabel<span class="operator">-</span><span class="operator">></span>setText(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>(<span class="string">"$%1"</span>)<span class="operator">.</span>arg(d)); } <span class="type">void</span> Dialog<span class="operator">::</span>setItem() { <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> items; items <span class="operator"><</span><span class="operator"><</span> tr(<span class="string">"Spring"</span>) <span class="operator"><</span><span class="operator"><</span> tr(<span class="string">"Summer"</span>) <span class="operator"><</span><span class="operator"><</span> tr(<span class="string">"Fall"</span>) <span class="operator"><</span><span class="operator"><</span> tr(<span class="string">"Winter"</span>); bool ok; <span class="type"><a href="../qtcore/qstring.html">QString</a></span> item <span class="operator">=</span> <span class="type"><a href="qinputdialog.html">QInputDialog</a></span><span class="operator">::</span>getItem(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QInputDialog::getItem()"</span>)<span class="operator">,</span> tr(<span class="string">"Season:"</span>)<span class="operator">,</span> items<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="keyword">false</span><span class="operator">,</span> <span class="operator">&</span>ok); <span class="keyword">if</span> (ok <span class="operator">&</span><span class="operator">&</span> <span class="operator">!</span>item<span class="operator">.</span>isEmpty()) itemLabel<span class="operator">-</span><span class="operator">></span>setText(item); } <span class="type">void</span> Dialog<span class="operator">::</span>setText() { bool ok; <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text <span class="operator">=</span> <span class="type"><a href="qinputdialog.html">QInputDialog</a></span><span class="operator">::</span>getText(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QInputDialog::getText()"</span>)<span class="operator">,</span> tr(<span class="string">"User name:"</span>)<span class="operator">,</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span><span class="operator">::</span>Normal<span class="operator">,</span> <span class="type"><a href="../qtcore/qdir.html">QDir</a></span><span class="operator">::</span>home()<span class="operator">.</span>dirName()<span class="operator">,</span> <span class="operator">&</span>ok); <span class="keyword">if</span> (ok <span class="operator">&</span><span class="operator">&</span> <span class="operator">!</span>text<span class="operator">.</span>isEmpty()) textLabel<span class="operator">-</span><span class="operator">></span>setText(text); } <span class="type">void</span> Dialog<span class="operator">::</span>setMultiLineText() { bool ok; <span class="type"><a href="../qtcore/qstring.html">QString</a></span> text <span class="operator">=</span> <span class="type"><a href="qinputdialog.html">QInputDialog</a></span><span class="operator">::</span>getMultiLineText(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QInputDialog::getMultiLineText()"</span>)<span class="operator">,</span> tr(<span class="string">"Address:"</span>)<span class="operator">,</span> <span class="string">"John Doe\nFreedom Street"</span><span class="operator">,</span> <span class="operator">&</span>ok); <span class="keyword">if</span> (ok <span class="operator">&</span><span class="operator">&</span> <span class="operator">!</span>text<span class="operator">.</span>isEmpty()) multiLineTextLabel<span class="operator">-</span><span class="operator">></span>setText(text); } <span class="type">void</span> Dialog<span class="operator">::</span>setColor() { <span class="keyword">const</span> <span class="type"><a href="qcolordialog.html">QColorDialog</a></span><span class="operator">::</span>ColorDialogOptions options <span class="operator">=</span> <span class="type"><a href="../qtcore/qflag.html">QFlag</a></span>(colorDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>value()); <span class="keyword">const</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> color <span class="operator">=</span> <span class="type"><a href="qcolordialog.html">QColorDialog</a></span><span class="operator">::</span>getColor(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>green<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="string">"Select Color"</span><span class="operator">,</span> options); <span class="keyword">if</span> (color<span class="operator">.</span>isValid()) { colorLabel<span class="operator">-</span><span class="operator">></span>setText(color<span class="operator">.</span>name()); colorLabel<span class="operator">-</span><span class="operator">></span>setPalette(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span>(color)); colorLabel<span class="operator">-</span><span class="operator">></span>setAutoFillBackground(<span class="keyword">true</span>); } } <span class="type">void</span> Dialog<span class="operator">::</span>setFont() { <span class="keyword">const</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>FontDialogOptions options <span class="operator">=</span> <span class="type"><a href="../qtcore/qflag.html">QFlag</a></span>(fontDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>value()); bool ok; <span class="type"><a href="../qtgui/qfont.html">QFont</a></span> font <span class="operator">=</span> <span class="type"><a href="qfontdialog.html">QFontDialog</a></span><span class="operator">::</span>getFont(<span class="operator">&</span>ok<span class="operator">,</span> <span class="type"><a href="../qtgui/qfont.html">QFont</a></span>(fontLabel<span class="operator">-</span><span class="operator">></span>text())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> <span class="string">"Select Font"</span><span class="operator">,</span> options); <span class="keyword">if</span> (ok) { fontLabel<span class="operator">-</span><span class="operator">></span>setText(font<span class="operator">.</span>key()); fontLabel<span class="operator">-</span><span class="operator">></span>setFont(font); } } <span class="type">void</span> Dialog<span class="operator">::</span>setExistingDirectory() { <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>Options options <span class="operator">=</span> <span class="type"><a href="../qtcore/qflag.html">QFlag</a></span>(fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>value()); options <span class="operator">|</span><span class="operator">=</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>DontResolveSymlinks <span class="operator">|</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>ShowDirsOnly; <span class="type"><a href="../qtcore/qstring.html">QString</a></span> directory <span class="operator">=</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>getExistingDirectory(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QFileDialog::getExistingDirectory()"</span>)<span class="operator">,</span> directoryLabel<span class="operator">-</span><span class="operator">></span>text()<span class="operator">,</span> options); <span class="keyword">if</span> (<span class="operator">!</span>directory<span class="operator">.</span>isEmpty()) directoryLabel<span class="operator">-</span><span class="operator">></span>setText(directory); } <span class="type">void</span> Dialog<span class="operator">::</span>setOpenFileName() { <span class="keyword">const</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>Options options <span class="operator">=</span> <span class="type"><a href="../qtcore/qflag.html">QFlag</a></span>(fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>value()); <span class="type"><a href="../qtcore/qstring.html">QString</a></span> selectedFilter; <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>getOpenFileName(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QFileDialog::getOpenFileName()"</span>)<span class="operator">,</span> openFileNameLabel<span class="operator">-</span><span class="operator">></span>text()<span class="operator">,</span> tr(<span class="string">"All Files (*);;Text Files (*.txt)"</span>)<span class="operator">,</span> <span class="operator">&</span>selectedFilter<span class="operator">,</span> options); <span class="keyword">if</span> (<span class="operator">!</span>fileName<span class="operator">.</span>isEmpty()) openFileNameLabel<span class="operator">-</span><span class="operator">></span>setText(fileName); } <span class="type">void</span> Dialog<span class="operator">::</span>setOpenFileNames() { <span class="keyword">const</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>Options options <span class="operator">=</span> <span class="type"><a href="../qtcore/qflag.html">QFlag</a></span>(fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>value()); <span class="type"><a href="../qtcore/qstring.html">QString</a></span> selectedFilter; <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> files <span class="operator">=</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>getOpenFileNames( <span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QFileDialog::getOpenFileNames()"</span>)<span class="operator">,</span> openFilesPath<span class="operator">,</span> tr(<span class="string">"All Files (*);;Text Files (*.txt)"</span>)<span class="operator">,</span> <span class="operator">&</span>selectedFilter<span class="operator">,</span> options); <span class="keyword">if</span> (files<span class="operator">.</span>count()) { openFilesPath <span class="operator">=</span> files<span class="operator">[</span><span class="number">0</span><span class="operator">]</span>; openFileNamesLabel<span class="operator">-</span><span class="operator">></span>setText(<span class="type"><a href="../qtcore/qstring.html">QString</a></span>(<span class="string">"[%1]"</span>)<span class="operator">.</span>arg(files<span class="operator">.</span>join(<span class="string">", "</span>))); } } <span class="type">void</span> Dialog<span class="operator">::</span>setSaveFileName() { <span class="keyword">const</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>Options options <span class="operator">=</span> <span class="type"><a href="../qtcore/qflag.html">QFlag</a></span>(fileDialogOptionsWidget<span class="operator">-</span><span class="operator">></span>value()); <span class="type"><a href="../qtcore/qstring.html">QString</a></span> selectedFilter; <span class="type"><a href="../qtcore/qstring.html">QString</a></span> fileName <span class="operator">=</span> <span class="type"><a href="qfiledialog.html">QFileDialog</a></span><span class="operator">::</span>getSaveFileName(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QFileDialog::getSaveFileName()"</span>)<span class="operator">,</span> saveFileNameLabel<span class="operator">-</span><span class="operator">></span>text()<span class="operator">,</span> tr(<span class="string">"All Files (*);;Text Files (*.txt)"</span>)<span class="operator">,</span> <span class="operator">&</span>selectedFilter<span class="operator">,</span> options); <span class="keyword">if</span> (<span class="operator">!</span>fileName<span class="operator">.</span>isEmpty()) saveFileNameLabel<span class="operator">-</span><span class="operator">></span>setText(fileName); } <span class="type">void</span> Dialog<span class="operator">::</span>criticalMessage() { <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>StandardButton reply; reply <span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>critical(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QMessageBox::critical()"</span>)<span class="operator">,</span> MESSAGE<span class="operator">,</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Abort <span class="operator">|</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Retry <span class="operator">|</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Ignore); <span class="keyword">if</span> (reply <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Abort) criticalLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Abort"</span>)); <span class="keyword">else</span> <span class="keyword">if</span> (reply <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Retry) criticalLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Retry"</span>)); <span class="keyword">else</span> criticalLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Ignore"</span>)); } <span class="type">void</span> Dialog<span class="operator">::</span>informationMessage() { <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>StandardButton reply; reply <span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>information(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QMessageBox::information()"</span>)<span class="operator">,</span> MESSAGE); <span class="keyword">if</span> (reply <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Ok) informationLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"OK"</span>)); <span class="keyword">else</span> informationLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Escape"</span>)); } <span class="type">void</span> Dialog<span class="operator">::</span>questionMessage() { <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>StandardButton reply; reply <span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>question(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">"QMessageBox::question()"</span>)<span class="operator">,</span> MESSAGE<span class="operator">,</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Yes <span class="operator">|</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>No <span class="operator">|</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Cancel); <span class="keyword">if</span> (reply <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Yes) questionLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Yes"</span>)); <span class="keyword">else</span> <span class="keyword">if</span> (reply <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>No) questionLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"No"</span>)); <span class="keyword">else</span> questionLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Cancel"</span>)); } <span class="type">void</span> Dialog<span class="operator">::</span>warningMessage() { <span class="type"><a href="qmessagebox.html">QMessageBox</a></span> msgBox(<span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>Warning<span class="operator">,</span> tr(<span class="string">"QMessageBox::warning()"</span>)<span class="operator">,</span> MESSAGE<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="keyword">this</span>); msgBox<span class="operator">.</span>setDetailedText(MESSAGE_DETAILS); msgBox<span class="operator">.</span>addButton(tr(<span class="string">"Save &Again"</span>)<span class="operator">,</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>AcceptRole); msgBox<span class="operator">.</span>addButton(tr(<span class="string">"&Continue"</span>)<span class="operator">,</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>RejectRole); <span class="keyword">if</span> (msgBox<span class="operator">.</span>exec() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>AcceptRole) warningLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Save Again"</span>)); <span class="keyword">else</span> warningLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"Continue"</span>)); } <span class="type">void</span> Dialog<span class="operator">::</span>errorMessage() { errorMessageDialog<span class="operator">-</span><span class="operator">></span>showMessage( tr(<span class="string">"This dialog shows and remembers error messages. "</span> <span class="string">"If the checkbox is checked (as it is by default), "</span> <span class="string">"the shown message will be shown again, "</span> <span class="string">"but if the user unchecks the box the message "</span> <span class="string">"will not appear again if QErrorMessage::showMessage() "</span> <span class="string">"is called with the same message."</span>)); errorLabel<span class="operator">-</span><span class="operator">></span>setText(tr(<span class="string">"If the box is unchecked, the message "</span> <span class="string">"won't appear again."</span>)); } </pre> </div> <!-- @@@dialogs/standarddialogs/dialog.cpp --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>