Update ImageGestures example
- Update screenshot - Provide some information text on the screen when no images are found - Add all supported image formats to the file filters - Minor fixes according to our coding conventions: eg. don't shadow variables Fixes: QTBUG-119979 Change-Id: If41adf34f38bfa101f2c5433082828c1a10668b1 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 30e6d822327d8105d209af10d077512f21ecc12c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
2b18f6c7b8
commit
e4c533c336
Binary file not shown.
Before Width: | Height: | Size: 38 KiB |
BIN
examples/widgets/doc/images/imagegestures-example.png
Normal file
BIN
examples/widgets/doc/images/imagegestures-example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 293 KiB |
@ -10,7 +10,7 @@
|
||||
This example shows how to enable gestures for a widget and use gesture input
|
||||
to perform actions.
|
||||
|
||||
\image imagegestures-example.jpg
|
||||
\image imagegestures-example.png
|
||||
|
||||
We use two classes to create the user interface for the application: \c MainWidget
|
||||
and \c ImageWidget. The \c MainWidget class is simply used as a container for the
|
||||
|
@ -41,6 +41,12 @@ void ImageWidget::paintEvent(QPaintEvent*)
|
||||
{
|
||||
QPainter p(this);
|
||||
|
||||
if (files.isEmpty() && !path.isEmpty()) {
|
||||
p.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap,
|
||||
tr("No supported image formats found"));
|
||||
return;
|
||||
}
|
||||
|
||||
const qreal iw = currentImage.width();
|
||||
const qreal ih = currentImage.height();
|
||||
const qreal wh = height();
|
||||
@ -144,11 +150,15 @@ void ImageWidget::resizeEvent(QResizeEvent*)
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageWidget::openDirectory(const QString &path)
|
||||
void ImageWidget::openDirectory(const QString &url)
|
||||
{
|
||||
this->path = path;
|
||||
path = url;
|
||||
QDir dir(path);
|
||||
const QStringList nameFilters{"*.jpg", "*.png"};
|
||||
|
||||
QStringList nameFilters;
|
||||
const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
|
||||
for (const QByteArray &format : supportedFormats)
|
||||
nameFilters.append(QLatin1String("*.") + QString::fromLatin1(format));
|
||||
files = dir.entryInfoList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
|
||||
|
||||
position = 0;
|
||||
|
@ -25,7 +25,7 @@ class ImageWidget : public QWidget
|
||||
|
||||
public:
|
||||
ImageWidget(QWidget *parent = nullptr);
|
||||
void openDirectory(const QString &path);
|
||||
void openDirectory(const QString &url);
|
||||
void grabGestures(const QList<Qt::GestureType> &gestures);
|
||||
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user