I have dimension companent problem on my phone
-
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
#endifQScreen *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.
@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 ]
-
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.
-
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.
-
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/
-
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++@ZekDe yes, you can.
It is described in the link @sierdzio posted: https://qmlbook.github.io/en/ch16/index.html -
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);