Manual dialogs test: Add about dialog showing style and scaling

Change-Id: I8750956056466d3cfd99903fb5e432ac81223403
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Friedemann Kleint 2018-04-05 09:47:48 +02:00
parent 3a912e92bb
commit 807f819357

View File

@ -33,10 +33,13 @@
#include "wizardpanel.h"
#include "messageboxpanel.h"
#include <QLibraryInfo>
#include <QDialogButtonBox>
#include <QMainWindow>
#include <QApplication>
#include <QMenuBar>
#include <QTabWidget>
#include <QFormLayout>
#include <QMenu>
#include <QAction>
#include <QKeySequence>
@ -44,10 +47,40 @@
// Test for dialogs, allowing to play with all dialog options for implementing native dialogs.
// Compiles with Qt 4.8 and Qt 5.
class AboutDialog : public QDialog
{
public:
explicit AboutDialog(QWidget *parent = 0);
};
AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
QFormLayout *mainLayout = new QFormLayout(this);
#if QT_VERSION >= 0x050600
mainLayout->addRow(new QLabel(QLibraryInfo::build()));
#else
mainLayout->addRow(new QLabel(QLatin1String("Qt ") + QLatin1String(QT_VERSION_STR )));
#endif
mainLayout->addRow("Style:", new QLabel(qApp->style()->objectName()));
#if QT_VERSION >= 0x050600
mainLayout->addRow("DPR:", new QLabel(QString::number(qApp->devicePixelRatio())));
#endif
const QString resolution = QString::number(logicalDpiX()) + QLatin1Char(',')
+ QString::number(logicalDpiY()) + QLatin1String("dpi");
mainLayout->addRow("Resolution:", new QLabel(resolution));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
mainLayout->addRow(buttonBox);
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
public slots:
void aboutDialog();
};
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
@ -66,6 +99,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
action->setShortcut(QKeySequence(QKeySequence::Paste));
action = editMenu->addAction(tr("Select All"));
action->setShortcut(QKeySequence(QKeySequence::SelectAll));
QMenu *aboutMenu = menuBar()->addMenu(tr("&About"));
QAction *aboutAction = aboutMenu->addAction(tr("About..."), this, SLOT(aboutDialog()));
aboutAction->setShortcut(Qt::Key_F1);
QTabWidget *tabWidget = new QTabWidget;
tabWidget->addTab(new FileDialogPanel, tr("QFileDialog"));
tabWidget->addTab(new ColorDialogPanel, tr("QColorDialog"));
@ -78,6 +114,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
setCentralWidget(tabWidget);
}
void MainWindow::aboutDialog()
{
AboutDialog dialog(this);
dialog.setWindowTitle(tr("About Dialogs"));
dialog.exec();
}
int main(int argc, char *argv[])
{
#if QT_VERSION >= 0x050700