Some questions for developping an app for Android and iOS
-
Hi, i'm a beginner in Qt (and in developpment in general) and I have a couple of questions.
I'm developping a program which is supposed to works and looks the same (as much as possible) on iOS and on Android, but i'm having some issues... i usually search on google or on the documentation for this, but i don't know how to express theses ones.
1- I have a fairly simple code (some widgets in a QGridLayout, done only by code, no designer and no Qt quick). The thing is, the size of the QLabel, which i set manually with setPixelSize, differ from android to iOS. For example, 30 is kinda big for iOS, but normal for Android.
My question is, is there a code (something like a "if") to check if i compile for android of for iOS ? Something likeif "Android" => size= 50
else if "iOS" => size = 302- I use a QLabel with a QPixmap to show some image on my application. It works for iOS, but the image don't show on Android, why ?
3- How do you allow you application to have specific parameters, which can be set in the setting on the IPhone ?
Thanks for reading me and answering =).
-
"iOS":http://qt-project.org/doc/qt-5/qtglobal.html#Q_OS_IOS "Android":http://qt-project.org/doc/qt-5/qtglobal.html#Q_OS_ANDROID
Don't know
Take look on "QSettings":http://qt-project.org/doc/qt-5/qsettings.html#details
-
- I think I have answered this a few times in this forum, my solution for this problem as the short answer: I use a custom device independent factor I can multiply with all size values so it looks the same on every device:
@
#if defined(Q_OS_ANDROID)
m_dipNorm = 160;
#elif defined(Q_OS_IOS)
m_dipNorm = 120; // TODO find optimal factor
#else
m_dipNorm = 96;
#endif
QScreen *screen = qApp->primaryScreen();
m_dipScaleFactor = screen->physicalDotsPerInch() / screen->devicePixelRatio() / m_dipNorm;
@
So I use this "m_dipScaleFactor" for every width, height, spacing, font size and whatever you want to scale with the DPI. I hope that helps you a little. - I think I have answered this a few times in this forum, my solution for this problem as the short answer: I use a custom device independent factor I can multiply with all size values so it looks the same on every device:
-
Xander84 is the word "dip" in the variable names typo and it means dpi or is it something else?
-
Actually that is no typo, I adopted that style from the Android dimension: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
dip or dp stands for Density-independent Pixels :)I usually use QML and my layout files look like this:
@
Rectangle {
width: 50dp
height. 20dp
}
Text {
font.pixelSize: 12*sp
}
@
so similar to android layout files with the dimensions "dp" and "sp" but I have to multiply the factor and can't just write 50dp or 12sp in QMl, but that is a small sacrifice, as long as it works as expected and Qt has nothing like this built in as far as I know!? -
Thank you for the explanation. I was puzzled when I've seen your example first time, so decided to clarify it for myself.
-
Thanks for the answers, it helps indeed =) .
Still, no idea on why my images work on iOS but not on Android? Is the QPixmap method wrong ?
-
Hi,
How do you provide your image to your application ?
-
Hi, well, very simple (i think):
@m_picture = new QLabel();
m_picture->setPixmap(QPixmap("/.../.png");
gridlayout->addWidget(m_picture, 0, 4)@ -
Hi, maybe too simple. :D
I think you should use Qt resource files for the image, that works great on all platforms. If the resources are not that large you can simply use a resource file so the images will be packed into the executable and not deployed separately.You can read more about the Qt Resource System here: http://qt-project.org/doc/qt-5/resources.html
-
Digging a old thread, but i thought a thanks was in order, as your solution did the trick, i'm now using a Qrc thank you =).