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. I have dimension companent problem on my phone

I have dimension companent problem on my phone

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 3 Posters 2.3k 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.
  • X Xander84

    Yeah sorry I was just assuming nobody uses Qt widget layouts on mobile devices, just my opinion but I think it's a lot easier and faster with QML (among other things).
    But this doesn't change the fact, you can do the same with "old" widgets, but not in the designer, only if you create the UI via code because .ui form layouts can't have any code attached as far as I know they are just "static" layouts.
    I haven't used widget layouts for some time now, but as far as I remember there is a setupUi method in every controller c++ file (or moc file?) and you can apply the device independent scaling there if you need to.

    Actually my code above was just an example in pure QML, in my app I use c++ for that like this (excerpt):
    @
    ...
    #if defined(Q_OS_ANDROID)
    m_dipNorm = 160;
    #elif defined(Q_OS_IOS)
    m_dipNorm = 160; // TODO test different sizes
    #else
    m_dipNorm = 96; // desktop norm
    #endif

    QScreen *screen = qApp->primaryScreen();
    m_dipScaleFactor = screen->physicalDotsPerInch() / screen->devicePixelRatio() / m_dipNorm;
    @
    So I use the m_dipScaleFactor value to scale essentially all sizes for layouts and margins etc. For font sizes I have another value with an extra font scale factor like android apps use dp or dip for sizes and sp or sip for scaleble font sizes.

    I just don't know how to best integrate a dynamic factor into widget forms, maybe you have some ideas for that?

    By the way one nice effect of this scaling stuff is that you can zoom the whole layout with this, in my app i can zoom in or out as I please, so the complete app changes size and margins, spacing between elements and font size. also font size can be scaled independently without layout size changes.

    Z Offline
    Z Offline
    ZekDe
    wrote on last edited by A Former User
    #1

    @Xander84 said in Qt on Android layouts all wrong:

    QScreen *screen = qApp->primaryScreen();
    m_dipScaleFactor = screen->physicalDotsPerInch() / screen->devicePixelRatio() / m_dipNorm;

    I have dimension companent problem on my phone ,small objects.Could you explain better how I can solve this problem.I am new at Qt. Thanks.

    [Edit: The original thread is dead for many years now and the users who posted there aren't active on this forum anymore. Please elaborate on your problem and give your thread a meaningful title. ~~ @Wieland ]

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Well, bump your scale factor. Or use QtQuick.Controls 2, which have DPI scaling fixed and done automatically.

      Also, see the docs: link. That method is known to report dubious values on Android.

      (Z(:^

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        ZekDe
        wrote on last edited by
        #3

        Okay ,but Can I use with C++ together.both C++ and QtQuick .Also How can I use Qtquick ,could you offer a source for this

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Sure, you can use QML and C++ together. That's the point, actually ;-) To keep logic in C++ and UI in QML.

          But now that you've asked that question, I am confused. Is your application built using QtWidgets module? Or are you building something fresh from scratch? If you're doing something new, it is a good idea to start with QtQuick, sure. If you already have an app written with widgets, it may be an overkill to try and rewrite it - then it would be better to just tweak your scale factor on Android and hope for the best.

          (Z(:^

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZekDe
            wrote on last edited by
            #5

            I couldn't excatly understand ,what you mean,but I am gonna try to tell you my work.I choosed application selection -> Qt Widgets Application then -> next and-> Android for armeabi-v7a then my projects is opened.Base Class is choosed as QMainWindow.All I did is this and some forum application.

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Widget applications are not very well suited for mobile platforms. You'll be better of starting a new project "Qt Quick application".

              Also, to make the learning curve more enjoyable, I recommend reading https://qmlbook.github.io/

              (Z(:^

              1 Reply Last reply
              1
              • Z Offline
                Z Offline
                ZekDe
                wrote on last edited by
                #7

                Thanks informations,
                Last question(I think last question :) .When I created a button in Qt Quick ,then can I program it with C++ ,and other companents.Because I like using C++ and I would like to use mostly C++

                jsulmJ 1 Reply Last reply
                0
                • Z ZekDe

                  Thanks informations,
                  Last question(I think last question :) .When I created a button in Qt Quick ,then can I program it with C++ ,and other companents.Because I like using C++ and I would like to use mostly C++

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @ZekDe yes, you can.
                  It is described in the link @sierdzio posted: https://qmlbook.github.io/en/ch16/index.html

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • Z Offline
                    Z Offline
                    ZekDe
                    wrote on last edited by
                    #9

                    Okay now ,I did it with C++ using like this

                    int h = screenGeometry.height();
                    int w = screenGeometry.width();
                    int hh = (3*h/sf1) + h/sf_title + h/sf_bluetooth;
                    hh = h - hh;
                    //qreal qrlX = screen->physicalDotsPerInchX(); // tek eksende alma yeterli
                    //qreal qrlY = screen->physicalDotsPerInchY();
                    screenGeometry.setX(w);
                    screenGeometry.setY(h);

                    /// \brief labelTitle
                    ///
                    QFont fontTitle("Courier", round(h/87), QFont::Bold);
                    ui->labelTitle->setGeometry(w/sf1,h/sf1,w-w/sf1,h/sf_title);
                    ui->labelTitle->setFont(fontTitle);
                    ui->labelTitle->setStyleSheet(QStringLiteral("color: #0095d6"));
                    ui->labelTitle->setAlignment(Qt::AlignHCenter);
                    
                    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