Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Some questions for developping an app for Android and iOS
Forum Updated to NodeBB v4.3 + New Features

Some questions for developping an app for Android and iOS

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 4 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Whiden
    wrote on last edited by
    #1

    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 like

    if "Android" => size= 50
    else if "iOS" => size = 30

    2- 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 =).

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      "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

      1 Reply Last reply
      0
      • X Offline
        X Offline
        Xander84
        wrote on last edited by
        #3
        1. 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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          Xander84 is the word "dip" in the variable names typo and it means dpi or is it something else?

          1 Reply Last reply
          0
          • X Offline
            X Offline
            Xander84
            wrote on last edited by
            #5

            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. 20
            dp
            }
            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!?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #6

              Thank you for the explanation. I was puzzled when I've seen your example first time, so decided to clarify it for myself.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                Whiden
                wrote on last edited by
                #7

                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 ?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  How do you provide your image to your application ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    Whiden
                    wrote on last edited by
                    #9

                    Hi, well, very simple (i think):

                    @m_picture = new QLabel();
                    m_picture->setPixmap(QPixmap("/.../.png");
                    gridlayout->addWidget(m_picture, 0, 4)@

                    1 Reply Last reply
                    0
                    • X Offline
                      X Offline
                      Xander84
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        Whiden
                        wrote on last edited by
                        #11

                        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 =).

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved