eudoxos
eudoxos

Reputation: 19075

QML: select image on Android (without java bridges and stuff)

I would like to select an image from existing files in an app written in Qt 5.9 (using Qt Quick and some c++). I tried to use FileDialog from QML (official example here) but when I run it in the emulator, it looks like this: funny open dialog

I did read this blogpost http://amin-ahmadi.com/2015/12/08/how-to-open-android-image-gallery-in-qt/ which explains how to use native code for gallery chooser though I am wondering if meanwhile Qt progressed to make such task readily available in a more straightforward manner.

EDIT: A hint is that FileDialog.shortcut documented here says:

The directory containing the user's pictures or photos. It is always a kind of file: URL; but on some platforms, it will be specialized, such that the FileDialog will be realized as a gallery browser dialog.

Upvotes: 3

Views: 1501

Answers (2)

Alex Huber
Alex Huber

Reputation: 503

There is also a QML component available to display and select single or multiple images. You can find more info here: https://felgo.com/updates/release-3-2-0-qt-5-12-3-subscriptions

You can also test it right on your mobile phone: https://felgo.com/web-editor/?snippet=77c7ad94

Upvotes: 0

JaTe
JaTe

Reputation: 21

Better late than never:

Your application probably uses high DPI scaling, which automatically scales the QtQuick.Controls 2 on displays with higher DPI. In main.cpp:

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

Basically the px sizes in your app don't represent physical pixels anymore. Some (older) Qt components, one of those is the FileDialog, don't work as expected on that setting. Removing it should fix your problem, but will probably affect the visual appearance of you app. More Info: https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/

You could try to build your own FileDialog with the FolderListModel: https://doc.qt.io/qt-5/qml-qt-labs-folderlistmodel-folderlistmodel.html

Upvotes: 1

Related Questions