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. [Solved] Qt on Android, problem with screen resolution.
Forum Updated to NodeBB v4.3 + New Features

[Solved] Qt on Android, problem with screen resolution.

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 3 Posters 2.7k Views 2 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.
  • mrdebugM Offline
    mrdebugM Offline
    mrdebug
    wrote on last edited by mrdebug
    #1

    One of my problems is to write an application usable for all mobiles types.
    I have to use font size= 28 for Samsung S5 mobile and 16 for a little mobile.
    Is there a way to set the sizes, borders, dimension automatically for each device or have I to manage each screen size?
    I have found point size for font but for rectangles, borders How can I do?
    Have you got an example?

    Need programmers to hire?
    www.labcsp.com
    www.denisgottardello.it
    GMT+1
    Skype: mrdebug

    O A 2 Replies Last reply
    0
    • mrdebugM mrdebug

      One of my problems is to write an application usable for all mobiles types.
      I have to use font size= 28 for Samsung S5 mobile and 16 for a little mobile.
      Is there a way to set the sizes, borders, dimension automatically for each device or have I to manage each screen size?
      I have found point size for font but for rectangles, borders How can I do?
      Have you got an example?

      O Offline
      O Offline
      onek24
      wrote on last edited by onek24
      #2

      @mrdebug The QScreen class provides a few usefull functions: logicalDotsPerInch() and physicalDotsPerInch(). physicalDotsPerInch() returns the amount of pixels you have on an inch. You can design your application on a physical size in inch or cm, that will keep your objects resolutionindependent.

      Oh and by the way.. this might be usefull: ScreenSupport

      1 Reply Last reply
      0
      • mrdebugM Offline
        mrdebugM Offline
        mrdebug
        wrote on last edited by
        #3

        Ok, using qml have I to calculate the scale and then apply to all components?
        For example:

        Rectangle {
            anchors.bottomMargin: 4
            anchors.topMargin: 4
        anchors.rightMargin: 4
        anchors.leftMargin: 4
            border.width: 2
            anchors.fill: parent
        }
        

        should be

        Rectangle {
            anchors.bottomMargin: 4 * scale
            anchors.topMargin: 4 * scale
        anchors.rightMargin: 4 * scale
        anchors.leftMargin: 4 * scale
            border.width: 2 * scale
            anchors.fill: parent
        }
        

        where scale will be calculated using QScreen?

        Need programmers to hire?
        www.labcsp.com
        www.denisgottardello.it
        GMT+1
        Skype: mrdebug

        O 1 Reply Last reply
        0
        • mrdebugM mrdebug

          Ok, using qml have I to calculate the scale and then apply to all components?
          For example:

          Rectangle {
              anchors.bottomMargin: 4
              anchors.topMargin: 4
          anchors.rightMargin: 4
          anchors.leftMargin: 4
              border.width: 2
              anchors.fill: parent
          }
          

          should be

          Rectangle {
              anchors.bottomMargin: 4 * scale
              anchors.topMargin: 4 * scale
          anchors.rightMargin: 4 * scale
          anchors.leftMargin: 4 * scale
              border.width: 2 * scale
              anchors.fill: parent
          }
          

          where scale will be calculated using QScreen?

          O Offline
          O Offline
          onek24
          wrote on last edited by onek24
          #4

          I've wrote a few javascript functions for qml which might work good for you:

          function cm(cm){
                  if(Screen.pixelDensity)
                      return cm*Screen.pixelDensity*10
                  console.warn("Could not calculate 'cm' based on Screen.pixelDensity.")
                  return 0
              }
              function mm(mm){
                  if(Screen.pixelDensity)
                      return mm*Screen.pixelDensity
                  console.warn("Could not calculate 'mm' based on Screen.pixelDensity.")
                  return 0
              }
              function inch(i){
                  if(Screen.pixelDensity)
                      return i*Screen.pixelDensity*10*2.54
                  console.warn("Could not calculate 'inch' based on Screen.pixelDensity.")
                  return 0
              }
              function vw(i){
                  if(Screen.width)
                      return i*(Screen.width/100)
                  console.warn("Could not calculate 'vw' based on Screen.width.")
                  return 0
              }
              function vh(i){
                  if(Screen.height)
                      return i*(Screen.height/100)
                  console.warn("Could not calculate 'vh' based on Screen.height.")
                  return 0
              }
          

          Just add these functions to your root-component/window and you can access them from everywhere.
          Each function returns the pixels from the given system of measurement(which is the functionname). So let's say you want an rectangle which is 2 centimeters high and 4 inches wide:

          Rectangle {
              height: cm(2)
              width: inch(4)
          }
          

          VH and VW are actually viewport units. VH is 1% of the full height while VW is 1% of the full width.

          1 Reply Last reply
          0
          • mrdebugM mrdebug

            One of my problems is to write an application usable for all mobiles types.
            I have to use font size= 28 for Samsung S5 mobile and 16 for a little mobile.
            Is there a way to set the sizes, borders, dimension automatically for each device or have I to manage each screen size?
            I have found point size for font but for rectangles, borders How can I do?
            Have you got an example?

            A Offline
            A Offline
            alexvplay
            wrote on last edited by
            #5

            @mrdebug For further information about multiple screen sizes & densities this blog post summarizing our talk at last Qt Dev Days in Berlin might also help: http://v-play.net/2014/11/supporting-multiple-screen-sizes-and-screen-densities-with-qt-and-v-play/

            Alex from V-Play

            CoFounder of Felgo - https://felgo.com/qt

            Felgo simplifies Mobile App & Game Development with Qt
            What others say: Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

            1 Reply Last reply
            0
            • mrdebugM Offline
              mrdebugM Offline
              mrdebug
              wrote on last edited by
              #6

              Ok, now I have understand.

              Need programmers to hire?
              www.labcsp.com
              www.denisgottardello.it
              GMT+1
              Skype: mrdebug

              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