diff options
Diffstat (limited to 'examples/widgets')
14 files changed, 66 insertions, 62 deletions
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp index df77d03567..77549e60f8 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.cpp +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -492,7 +492,7 @@ void Dialog::questionMessage() void Dialog::warningMessage() { QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"), - MESSAGE, nullptr, this); + MESSAGE, { }, this); msgBox.setDetailedText(MESSAGE_DETAILS); msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole); msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole); diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc index af8766a308..d8d09612f6 100644 --- a/examples/widgets/doc/dropsite.qdoc +++ b/examples/widgets/doc/dropsite.qdoc @@ -176,16 +176,16 @@ \snippet draganddrop/dropsite/dropsitewindow.cpp constructor part3 - Two QPushButton objects, \c clearButton and \c quitButton, are instantiated - and added to \c buttonBox - a QDialogButtonBox object. We use - QDialogButtonBox here to ensure that the push buttons are presented in a + Three QPushButton objects, \c clearButton, \c copyButton, and \c quitButton, + are instantiated and added to \c buttonBox - a QDialogButtonBox object. We + use QDialogButtonBox here to ensure that the push buttons are presented in a layout that conforms to the platform's style. \snippet draganddrop/dropsite/dropsitewindow.cpp constructor part4 - The \l{QPushButton::clicked()}{clicked()} signals for \c quitButton and - \c clearButton are connected to \l{QWidget::close()}{close()} and - \c clear(), respectively. + The \l{QPushButton::clicked()}{clicked()} signals for \c copyButton, + \c clearButton, and \c quitButton are connected to \c copy(), + \c clear() and \l{QWidget::close()}{close()}, respectively. For the layout, we use a QVBoxLayout, \c mainLayout, to arrange our widgets vertically. We also set the window title to "Drop Site" and the minimum diff --git a/examples/widgets/doc/src/icons.qdoc b/examples/widgets/doc/src/icons.qdoc index 7aae0491d6..24be09a7a9 100644 --- a/examples/widgets/doc/src/icons.qdoc +++ b/examples/widgets/doc/src/icons.qdoc @@ -232,8 +232,8 @@ combinations of states and modes for a given icon. \li \c IconSizeSpinBox is a subclass of QSpinBox that lets the user enter icon sizes (e.g., "48 x 48"). - \li \c ImageDelegate is a subclass of QItemDelegate that provides - comboboxes for letting the user set the mode and state + \li \c ImageDelegate is a subclass of QStyledItemDelegate that + provides comboboxes for letting the user set the mode and state associated with an image. \endlist @@ -468,7 +468,6 @@ loaded into the application. \snippet widgets/icons/mainwindow.cpp 13 - \snippet widgets/icons/mainwindow.cpp 14 We retrieve the image name using the QFileInfo::baseName() function that returns the base name of the file without the path, @@ -486,8 +485,6 @@ Qt::ItemIsEditable flag. Table items are editable by default. \snippet widgets/icons/mainwindow.cpp 15 - \snippet widgets/icons/mainwindow.cpp 16 - \snippet widgets/icons/mainwindow.cpp 17 Then we create the second and third items in the row making the default mode Normal and the default state Off. But if the \uicontrol @@ -498,7 +495,6 @@ example's \c images subdirectory respect this naming convention. \snippet widgets/icons/mainwindow.cpp 18 - \snippet widgets/icons/mainwindow.cpp 19 In the end we add the items to the associated row, and use the QTableWidget::openPersistentEditor() function to create @@ -522,8 +518,6 @@ application. \snippet widgets/icons/mainwindow.cpp 8 - \snippet widgets/icons/mainwindow.cpp 9 - \snippet widgets/icons/mainwindow.cpp 10 We also extract the image file's name using the QTableWidgetItem::data() function. This function takes a @@ -571,24 +565,22 @@ delegate for the table widget. We create a \c ImageDelegate that we make the item delegate for our view. - The QItemDelegate class can be used to provide an editor for an item view + The QStyledItemDelegate class can be used to provide an editor for an item view class that is subclassed from QAbstractItemView. Using a delegate for this purpose allows the editing mechanism to be customized and developed independently from the model and view. - In this example we derive \c ImageDelegate from QItemDelegate. - QItemDelegate usually provides line editors, while our subclass + In this example we derive \c ImageDelegate from QStyledItemDelegate. + QStyledItemDelegate usually provides line editors, while our subclass \c ImageDelegate, provides comboboxes for the mode and state fields. \snippet widgets/icons/mainwindow.cpp 22 - \snippet widgets/icons/mainwindow.cpp 23 Then we customize the QTableWidget's horizontal header, and hide the vertical header. \snippet widgets/icons/mainwindow.cpp 24 - \snippet widgets/icons/mainwindow.cpp 25 At the end, we connect the QTableWidget::itemChanged() signal to the \c changeIcon() slot to ensure that the preview area is in @@ -750,23 +742,23 @@ \snippet widgets/icons/imagedelegate.h 0 - The \c ImageDelegate class is a subclass of QItemDelegate. The - QItemDelegate class provides display and editing facilities for - data items from a model. A single QItemDelegate object is + The \c ImageDelegate class is a subclass of QStyledItemDelegate. The + QStyledItemDelegate class provides display and editing facilities for + data items from a model. A single QStyledItemDelegate object is responsible for all items displayed in a item view (in our case, a QTableWidget). - A QItemDelegate can be used to provide an editor for an item view + A QStyledItemDelegate can be used to provide an editor for an item view class that is subclassed from QAbstractItemView. Using a delegate for this purpose allows the editing mechanism to be customized and developed independently from the model and view. \snippet widgets/icons/imagedelegate.h 1 - The default implementation of QItemDelegate creates a QLineEdit. + The default implementation of QStyledItemDelegate creates a QLineEdit. Since we want the editor to be a QComboBox, we need to subclass - QItemDelegate and reimplement the QItemDelegate::createEditor(), - QItemDelegate::setEditorData() and QItemDelegate::setModelData() + QStyledItemDelegate and reimplement the QStyledItemDelegate::createEditor(), + QStyledItemDelegate::setEditorData() and QStyledItemDelegate::setModelData() functions. \snippet widgets/icons/imagedelegate.h 2 @@ -783,7 +775,7 @@ \snippet widgets/icons/imagedelegate.cpp 1 - The default QItemDelegate::createEditor() implementation returns + The default QStyledItemDelegate::createEditor() implementation returns the widget used to edit the item specified by the model and item index for editing. The parent widget and style option are used to control the appearance of the editor widget. @@ -803,7 +795,7 @@ \snippet widgets/icons/imagedelegate.cpp 2 - The QItemDelegate::setEditorData() function is used by + The QStyledItemDelegate::setEditorData() function is used by QTableWidget to transfer data from a QTableWidgetItem to the editor. The data is stored as a string; we use QComboBox::findText() to locate it in the combobox. @@ -816,7 +808,7 @@ \snippet widgets/icons/imagedelegate.cpp 3 - The QItemDelegate::setEditorData() function is used by QTableWidget + The QStyledItemDelegate::setEditorData() function is used by QTableWidget to transfer data back from the editor to the \l{QTableWidgetItem}. \snippet widgets/icons/imagedelegate.cpp 4 diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp index 2dae83bb22..a937e24a4c 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp @@ -82,14 +82,21 @@ DropSiteWindow::DropSiteWindow() //! [constructor part4] clearButton = new QPushButton(tr("Clear")); + copyButton = new QPushButton(tr("Copy")); quitButton = new QPushButton(tr("Quit")); buttonBox = new QDialogButtonBox; buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole); + buttonBox->addButton(copyButton, QDialogButtonBox::ActionRole); +#if !QT_CONFIG(clipboard) + copyButton->setVisible(false); +#endif + buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close); connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear); + connect(copyButton, &QAbstractButton::clicked, this, &DropSiteWindow::copy); //! [constructor part4] //! [constructor part5] @@ -108,6 +115,7 @@ DropSiteWindow::DropSiteWindow() void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) { formatsTable->setRowCount(0); + copyButton->setEnabled(false); if (!mimeData) return; //! [updateFormatsTable() part1] @@ -145,5 +153,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData) } formatsTable->resizeColumnToContents(0); +#if QT_CONFIG(clipboard) + copyButton->setEnabled(formatsTable->rowCount() > 0); +#endif } //! [updateFormatsTable() part4] + +void DropSiteWindow::copy() +{ +#if QT_CONFIG(clipboard) + QString text; + for (int row = 0, rowCount = formatsTable->rowCount(); row < rowCount; ++row) + text += formatsTable->item(row, 0)->text() + ": " + formatsTable->item(row, 1)->text() + '\n'; + QGuiApplication::clipboard()->setText(text); +#endif +} diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h index d80476f369..a40b481637 100644 --- a/examples/widgets/draganddrop/dropsite/dropsitewindow.h +++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h @@ -72,6 +72,7 @@ public: public slots: void updateFormatsTable(const QMimeData *mimeData); + void copy(); private: DropArea *dropArea; @@ -79,6 +80,7 @@ private: QTableWidget *formatsTable; QPushButton *clearButton; + QPushButton *copyButton; QPushButton *quitButton; QDialogButtonBox *buttonBox; }; diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h index d7df2b7b4b..5aa0250a29 100644 --- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h +++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h @@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget Q_OBJECT public: - explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr); + explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { }); QRectF boundingRect() const override; void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp index eadd5fadb8..ad80a238aa 100644 --- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp +++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp @@ -53,7 +53,7 @@ #include <QtWidgets> SpreadSheetDelegate::SpreadSheetDelegate(QObject *parent) - : QItemDelegate(parent) + : QStyledItemDelegate(parent) {} QWidget *SpreadSheetDelegate::createEditor(QWidget *parent, diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h index c89459cadf..36c70d2391 100644 --- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h +++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.h @@ -51,9 +51,9 @@ #ifndef SPREADSHEETDELEGATE_H #define SPREADSHEETDELEGATE_H -#include <QItemDelegate> +#include <QStyledItemDelegate> -class SpreadSheetDelegate : public QItemDelegate +class SpreadSheetDelegate : public QStyledItemDelegate { Q_OBJECT diff --git a/examples/widgets/layouts/flowlayout/flowlayout.cpp b/examples/widgets/layouts/flowlayout/flowlayout.cpp index 5c59ae025c..9a488557cf 100644 --- a/examples/widgets/layouts/flowlayout/flowlayout.cpp +++ b/examples/widgets/layouts/flowlayout/flowlayout.cpp @@ -123,7 +123,7 @@ QLayoutItem *FlowLayout::takeAt(int index) //! [6] Qt::Orientations FlowLayout::expandingDirections() const { - return 0; + return { }; } //! [6] diff --git a/examples/widgets/mainwindows/mainwindow/colorswatch.h b/examples/widgets/mainwindows/mainwindow/colorswatch.h index 7f73e46f31..2bd9fd2891 100644 --- a/examples/widgets/mainwindows/mainwindow/colorswatch.h +++ b/examples/widgets/mainwindows/mainwindow/colorswatch.h @@ -62,7 +62,7 @@ class ColorSwatch : public QDockWidget Q_OBJECT public: - explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = 0); + explicit ColorSwatch(const QString &colorName, QMainWindow *parent = nullptr, Qt::WindowFlags flags = { }); void setCustomSizeHint(const QSize &size); QMenu *colorSwatchMenu() const { return menu; } diff --git a/examples/widgets/mainwindows/mainwindow/mainwindow.h b/examples/widgets/mainwindows/mainwindow/mainwindow.h index a2c9d30ded..3ce9732763 100644 --- a/examples/widgets/mainwindows/mainwindow/mainwindow.h +++ b/examples/widgets/mainwindows/mainwindow/mainwindow.h @@ -65,7 +65,7 @@ public: explicit MainWindow(const CustomSizeHintMap &customSizeHints, QWidget *parent = nullptr, - Qt::WindowFlags flags = 0); + Qt::WindowFlags flags = { }); public slots: void actionTriggered(QAction *action); diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp index 39c2e43134..4fd251aa1b 100644 --- a/examples/widgets/widgets/icons/imagedelegate.cpp +++ b/examples/widgets/widgets/icons/imagedelegate.cpp @@ -55,9 +55,8 @@ //! [0] ImageDelegate::ImageDelegate(QObject *parent) - : QItemDelegate(parent) -{ -} + : QStyledItemDelegate(parent) +{} //! [0] //! [1] diff --git a/examples/widgets/widgets/icons/imagedelegate.h b/examples/widgets/widgets/icons/imagedelegate.h index 3b76b78339..9d65304e2c 100644 --- a/examples/widgets/widgets/icons/imagedelegate.h +++ b/examples/widgets/widgets/icons/imagedelegate.h @@ -51,10 +51,10 @@ #ifndef IMAGEDELEGATE_H #define IMAGEDELEGATE_H -#include <QItemDelegate> +#include <QStyledItemDelegate> //! [0] -class ImageDelegate : public QItemDelegate +class ImageDelegate : public QStyledItemDelegate { Q_OBJECT @@ -72,7 +72,7 @@ public: //! [1] //! [2] private slots: void emitCommitData(); -}; //! [2] +}; #endif diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp index f342c18c4c..8e61260041 100644 --- a/examples/widgets/widgets/icons/mainwindow.cpp +++ b/examples/widgets/widgets/icons/mainwindow.cpp @@ -216,16 +216,13 @@ void MainWindow::changeIcon() QImage image(fileName); if (!image.isNull()) icon.addPixmap(QPixmap::fromImage(image), mode, state); -//! [8] //! [9] +//! [8] } -//! [9] //! [10] } -//! [10] - //! [11] previewArea->setIcon(icon); -} //! [11] +} void MainWindow::addSampleImages() { @@ -280,17 +277,15 @@ void MainWindow::loadImages(const QStringList &fileNames) .arg(QDir::toNativeSeparators(fileInfo.absolutePath()), fileInfo.fileName()) .arg(fileInfo2x.exists() ? fileInfo2x.fileName() : tr("<None>")) .arg(image.width()).arg(image.height()); -//! [13] //! [14] QTableWidgetItem *fileItem = new QTableWidgetItem(imageName); fileItem->setData(Qt::UserRole, fileName); fileItem->setIcon(QPixmap::fromImage(image)); fileItem->setFlags((fileItem->flags() | Qt::ItemIsUserCheckable) & ~Qt::ItemIsEditable); fileItem->setToolTip(toolTip); -//! [14] +//! [13] //! [15] QIcon::Mode mode = QIcon::Normal; -//! [15] //! [16] QIcon::State state = QIcon::Off; if (guessModeStateAct->isChecked()) { if (imageName.contains(QLatin1String("_act"), Qt::CaseInsensitive)) @@ -302,13 +297,11 @@ void MainWindow::loadImages(const QStringList &fileNames) if (imageName.contains(QLatin1String("_on"), Qt::CaseInsensitive)) state = QIcon::On; -//! [16] //! [17] +//! [15] } -//! [17] //! [18] imagesTable->setItem(row, 0, fileItem); -//! [18] //! [19] QTableWidgetItem *modeItem = new QTableWidgetItem(IconPreviewArea::iconModeNames().at(IconPreviewArea::iconModes().indexOf(mode))); modeItem->setToolTip(toolTip); @@ -321,9 +314,9 @@ void MainWindow::loadImages(const QStringList &fileNames) imagesTable->openPersistentEditor(stateItem); fileItem->setCheckState(Qt::Checked); +//! [18] } } -//! [19] void MainWindow::useHighDpiPixmapsChanged(int checkState) { @@ -350,9 +343,7 @@ QWidget *MainWindow::createImagesGroupBox() //! [21] //! [22] - QStringList labels; -//! [22] //! [23] - labels << tr("Image") << tr("Mode") << tr("State"); + const QStringList labels({tr("Image"), tr("Mode"), tr("State")}); imagesTable->horizontalHeader()->setDefaultSectionSize(90); imagesTable->setColumnCount(3); @@ -361,18 +352,17 @@ QWidget *MainWindow::createImagesGroupBox() imagesTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed); imagesTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed); imagesTable->verticalHeader()->hide(); -//! [23] +//! [22] //! [24] connect(imagesTable, &QTableWidget::itemChanged, -//! [24] //! [25] this, &MainWindow::changeIcon); QVBoxLayout *layout = new QVBoxLayout(imagesGroupBox); layout->addWidget(imagesTable); return imagesGroupBox; -} //! [25] +} //! [26] QWidget *MainWindow::createIconSizeGroupBox() @@ -428,8 +418,8 @@ QWidget *MainWindow::createIconSizeGroupBox() layout->addLayout(otherSizeLayout, 3, 0, 1, 2); layout->setRowStretch(4, 1); return iconSizeGroupBox; -} //! [27] +} void MainWindow::screenChanged() { |