Questions & Answers from Qt for Beginners Part 3 - QML and Qt Quick

Eric Magnuson

Eric Magnuson is a Qt Software Consultant at ICS. He has conducted numerous on-site corporate Qt and QML training courses and has developed applications in the medical, biotech and security industries. Eric graduated from Worcester Polytechnic Institute with a degree in Computer Science.

By Eric Magnuson | Friday, May 20, 2016

Get the full on-demand video here:

Do the Qt Quick Controls 2 include all the capabilities of Qt Quick Controls 1?

While they are similar, there are differences between the controls offered and the APIs. The Qt documentation does a good job of describing the differences. See

How would I create and size scroll bars for multiline text?

See the Qt documentation for ScrollBar and Flickable and the Scroll Bar Example.

How does the Text wrapMode work?

wrapMode is a property of the Text QML type and takes one of four values. See

Do you plan to explain more about focus/active focus with relation to component reusability? It's tricky to understand and use it in right way.

Yes, keyboard focus can be tricky to get right. This would be a good topic for a future webinar or blog post. We will try to cover this some time in the future.

If I upgrade to a new Qt version, do I need to update the import QtQuick etc version number? If not, what's the impact?

No. QML maintains API compatibility with older versions so you don't need to import the latest version unless you need to use new features of that version.

How can we debug a Qt Quick application?

Qt Creator includes a QML debugger. You can also use simpler methods like print or console.log statements in your code.

Does text input need a height parameter? If not, how does it determine focus since there is only a width parameter in the example that you showed?

By default it will use a height based on the font being used. The width does need to be defined though.

What is a the difference between a Window/Item/Rectangle as the root?

Item is the most basic visual type. Rectangle inherits from it add adds some more properties like color. Window is for a top-level window and provides some integration with the platform's window manager like setting flags, orientation, and position on the screen.

Can a TTF be stretched in QML, for example to be narrower?

By TTF do you mean TrueType font? You can set font properties for QML types like Text, but you are limited to the available properties like pixelSize and letterSpacing unless you use some trick like rendering to an image and then manipulating the image.

I'm trying to anchor some items in the ApplicationWindow, but seems that I can't do that. How I can arrange items in the ApplicationWindow?

You can get an error because an ApplicationWindow is not an Item. See this discussion here:

For developing Android applications, how can I set the window size without hardcoding width and height? 

The QML Screen type will return the size of the display at run time.

Can you discuss mobile development?

QML supports Android, iOS, and some Linux-based mobile platforms. Development is similar to embedded systems, with the differences mostly in how you build, deploy, and package the applications. Qt Creator can help with much of this. You may need to use the commercial version of Qt if you want to release it to some app stores.

Is there a Graphics View widget in QML?

There is no direct QML equivalent to the C++ Graphics View, but much of it can be done in QML. The QML Canvas type may also be applicable.

Would TreeView be a good choice for a nested structure that needs to dynamically change?

Yes, that should be suitable.

Can you give some tips on how to use the Qt3D module in QML? 

Qt3D is quite complex, with many QML types. We hope to cover this in a future webinar and/or blog posts. There may be a full day course on it at the Qt World Summit.

Can you recommend any good books for QML?

A list of Qt books is here: Of the Qt 5 books, the only one I am familiar with is "Qt 5 Cadaques" which is quite good but is still a work in progress.

Is there support for Drag and Drop during application run time?

See the QML types Drag, DragEvent, and DropArea.

What about input/output to a file or to a database?

These functions are typically best done in C++ using Qt's file, i/o, and database classes and exposing them to QML as needed.

Can you embed a video within a button rectangle?

I don't think you can do this with the standard Qt Quick controls or labs button types, but you should be able to create your own button element using a rectangle and embed a video inside it.

Can a Qt Quick application provide a .exe file that can be double clicked to start?

Typically you write some C++ code to wrap a QML application into an executable program. Qt Creator can generate the code to do this for you.

Can you provide criteria for choosing the best way develop a Qt Quick application or a C++ application?

Generally almost every Qt Quick application will have some QML and some C++ code, with QML being used for the GUI and C++ for lower-level, non-graphical, or performance critical code.

Have a question or add to the conversation: Log in Register