FAQ Database Discussion Community


QT5 qml receive c++ object in slot

qt,qml,qt5,qtquick2
i want to send a c++ object to QML via signal-slot. class TaskInfo : public QObject { Q_OBJECT Q_PROPERTY(QString name READ taskName) ... // constructors public: TaskInfo(); TaskInfo(QIODevice *in); TaskInfo(TaskInfo &&taskInfo); TaskInfo(const TaskInfo &taskInfo); // it's just copy all variable ... } and i have a class to send TaskInfo...

Partial update repeater QML

qt,qml,qtquick2
I'm facing a little issue with QML/C++ project. I'm using a repeater to draw points inside a Rectangle and those points come from a model. Here is my code : main.qml Rectangle { id: rect height:500 width:500 Repeater { id: pointsRepeater model: qListPoints Point { } } } qListPoints come...

setting wrapMode property of Text in ScrollView

qt,qml,qt5,qtquick2
I wrote QML like this: import QtQuick 2.2 import QtQuick.Controls 1.1 import QtQuick.Layouts 1.1 import App 0.1 ApplicationWindow { id: appWindow visible: true width: 300 height: 500 ColumnLayout { ScrollView { ColumnLayout { Text { width: 250 text: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...

Even width of Text and Textfield

qt,qml,qt5,qtquick2
I have a simple login form written in QML with a custom component, MediumText, and two TextFields. Unfortunately, I'm not able to properly align the elements, as shown by the following picture: I want the labels to the left (MediumText type), as well as the TextField instances on the right,...

How to access a QList of QObject* in QML and Qt?

c++,qt,qml,qt5,qtquick2
I need to have an array of class objects which should be accessible in Qt as well as QML. Considering http://stackoverflow.com/a/15830797/462608 following is what I have tried. Now I need to know how to read and write to the functions of ClassA through Qt and QML. See the print statement...

QML simple extention doesn't work

c++,qt,qml,qtquick2
I'm trying to extend QML with a C++ class. I've started by creating a simple class Line. It calls setters, but doesn't call getters and the paint method. Any ideas why? In QtQuick 1.x I should call setFlag(QGraphicsItem::ItemHasNoContents, false); in the constructor. Probably I should call something similar? Here is...

DPI-independent constant size in QML

qt,qml,qt5,qtquick2,qt-quick
I have a visual component in my app written in QML, Qt5. I want it to always have the width of 5 cm on the screen, no matter what device is used. If I set width: somevalue, then the DPI might differ among the devices which will result in different...

Qt.inputMethod.show () doesn't show any keyboard

qt,qml,qt5,qtquick2
Considering "Property and Method Changes" from here: TextInput and TextEdit's openSoftwareInputPanel() and closeSoftwareInputPanel() methods have been removed. Use the new Qt.inputMethod property and call Qt.inputMethod.show() Qt.inputMethod.hide() to show and hide the virtual keyboard. I've written the simple example below. import QtQuick 2.3 import QtQuick.Window 2.2 Window { id: root visible:...

QML (Qt 5): Overlay button on top left corner of resized image

qt,qml,qt5,qtquick2
I have this code (reduced to minimal): import QtQuick 2.0 import QtQuick.Controls 1.3 Item { Image { id: img source: "cluster.png" width: 150 height: 150 fillMode: Image.PreserveAspectFit } Button { id: butn anchors.left: img.left anchors.top: img.top width: 20 height: 20 text: "Push!" } } Which produces an image similar to...

QtQuick2 - QML reusable item focus changes when selecting/clicking outside/inside of root item

javascript,qt,focus,qml,qtquick2
How can I implement focus changing state into reusable QML component when I clicked or selected another item outside component body to call any event (highlight text, show/hide rectangle and etc). There is code I trying to implement highlight line under CheckBox text when item have focus, and hide that...

How to display TextField at the bottom of the screen

qml,textfield,qtquick2,sailfish-os
I want to display a TextField at the bottom of the screen in QML for SailfishOS. I attempted multiple tries but the TextField is always at the top of the screen. import QtQuick 2.0 import Sailfish.Silica 1.0 ApplicationWindow { id: screen anchors.fill: parent Item { width: parent.width; anchors.bottom: screen.bottom TextField...

Fill QML ListModel from nested models

qt,qml,qtquick2
I have the following C++ model structure: Manager // QAbstractListModel ↪ Slot // QAbstractListModel ↪ Processor // QAbstractListModel ↪ name // Q_PROPERTY I pass only the Manager reference to QML on instantiation. I need to fill the ComboBox with Processor names but I don't know how to fill up with...

QML MouseArea Overlap other widget

qt,qml,qtquick2,qtquickcontrols
Here is some simple QML code which contains a Button and a MouseArea. I want the Button to detect both left and right mouse clicks. Rectangle { anchors.fill:parent; width: 1302 height: 638 Button { id: button1 x: 378 y: 332 width: 194 height: 66 text: qsTr("Button") } MouseArea { id:...

The structure of a mobile app with Qt Quick Controls

android,qt,qt-quick,qtquick2,qtquickcontrols
In the old days of com.nokia.meego or even now with the Sailfish.Silica module you are using the "Pages" for navigation inside the app. What should be used instead when developing a mobile app for Android with the Qt Quick Controls?...

wrong coordinates white getting real position of item relative to its parent

qt,qml,qt-quick,qtquick2
I have simple scene with only 2 Rectangles. The difference is that first one uses absolute coordinates and second one uses anchors. In this case both of rectangles are placed on the same place. But I get different coordinates at all. import QtQuick 2.4 import QtQuick.Window 2.2 Window { visible:...

Сreate a copy of a rectangle in QML

qt,qml,qtquick2,qt-quick
I want to make an area, where a small rectangles appear in the places it where clicked. Later on I would try to add an ability to move those rectangles by dragging. After studying Help, I tried to accomplish this with a MouseArea and a Component containing a Rectangle. Then,...

Diiference between setContextProperty and setProperty of object

c++,qt,qml,qtquick2,qt-quick
I really confuse right now What's is the difference between QQmlApplicationEngine engine; engine.rootContext().setContextProperty("myObject",&userData); and object->setProperty("myObject", myObject) Here is the QML file ApplicationWindow { id: applicationWindow1 Item { id: propertyHolder property MyObject myObject } I had read how to use QML binding but still hasn't figure it out. Please help Thanks...

OCaml - Accessing absolute paths

ocaml,filepath,qtquick2
I'm developing an application where I implement the GUI in QtQuick and the logic in OCaml, using lablqt. In QtQuick I use a FileDialog to select a file. I need to use the path that the FileDialog returns in my OCaml program but I get an error every time I...

How to connect a destroyed signal of C++ object from QML?

javascript,qt,qml,qtquick2
I want to connect a destroyed signal of C++ QObject from QML so I did this: Rectangle { id: root width: 128 height: 128 Button { anchors.centerIn: parent text: "Click me" onClicked: { qobj.Component.onDestruction.connect(function(){console.log("It destroy")}) // qobj is set from c++ qobj.destroy() // should output "It destroy" } } But...

Editing a TextInput in a ScrollView

qt,scrollview,qml,qtquick2,qtquickcontrols
I have an issue with my QML. I'd like to edit a TextInput based on an action, setting the focus attribute to true. It works when the TextInput is located in a Rectangle, but not in a ScrollView. Here is an example: Item { id: main width: 640 height: 480...

QML XmlListModel messes sorting when delegated

qt,canvas,qml,qtquick2
I'm trying to get a Canvas to draw lines in the same order as presented in this xml-file: <root> <doc><nopeus>80.0</nopeus><aika>40.0</aika></doc> <doc><nopeus>110.0</nopeus><aika>80.0</aika></doc> <doc><nopeus>120.0</nopeus><aika>120.0</aika></doc>...

Qt Creator doesn't display QML folder

qt,qml,qt-creator,qtquick2,qt-quick
I have a Qt project in Qt Creator. I have a qrc file with the QMLs registered and everything works. However for some reason the "projects" view of Qt Creator doesn't show the QML folder (screenshot attached) like it does for any example project. I'm just curious. Why does QML...

QML. How to stretch Grid for all parent space

qt,qml,qtquick2
I have a custom button: import QtQuick 2.0 Rectangle { id: xobutton width: 100 height: 100 property string label: "?" border.width: 2 Text { id: xobuttonLabel text: label font.pointSize: 75 anchors.centerIn: parent } } It has a parent Rectangle: Rectangle { width: 500 height: 500 Grid { anchors.centerIn: parent rows:...

Align horizontalcenter in Column

qt,qml,qtquick2,qt-quick
Column documentation explains how to achieve this: However, I would like to achieve this: That is, all items inside the Column should be horizontally aligned to the center. anchors.horizontalCenter: parent.Center does not work. How can I obtain the desired result?...

Repeat state on mouse click QML

qt,qml,qtquick2
Within the code I have a State, a Transition and a RotationAnimation defined. After the property change takes place, i.e. after the rotation is set to 360, the onClicked handler is rendered mute and the animation will never be played again after subsequent MouseArea clicks. Here is my current code:...

Set rotation point of Rectangle

qt,rotation,qml,qtquick2,qt-quick
Is there a way to set rotation point in Rectangle and simply use rotation property without any other additional component? I want to rotate a Rectangle with binding property of rotation: value * 180 like this Rectangle{ id: body rotation: value anchors.centerIn: parent.Center antialiasing: true } onValueChanged: body.rotation = value...

Drag after long press

qt,qml,drag,qtquick2
I want to drag my custom buttons QML after a long press over them. I've implemented that behaviour, however the problem is that after enabling drag, I need to press button once again to actually start dragging. How should I implement this mechanism if I want to move buttons without...

MouseArea event is propagated to its parent sibling. Why?

qt,qml,qt-quick,qtquick2
Here's a code snippet with current form of the code Rectangle { id: menu GridLayout { id: layout columns: 4 rows: 3 Repeater { model: ListModel {} ToolButton {} } Rectangle { x: -3 y: -33 width: menu.width - 2 height: menu.height + 33 border.color: "red" border.width: 3 color: "blue"...

Why Qt QML doesn't properly bind properties?

c++,qt,qml,qt5,qtquick2
It's very weird because I use almost the same pattern in another QML file and it works correctly! I'm sure I'm not reassigning value anywhere (the only thing I know that can make property static)! I have something like this (it's a simplified example and probably works as expected): Item...

Access Flickable from parent element

qml,qtquick2,flickable
I'm trying to call a function which is defined inside a Flickable element, but it seems impossible to access it by id. The following code produces ReferenceError: flickable is not defined when tab.getValues() is called: import QtQuick 2.4 Tab { id: tab function getValues() { flickable.getValues() } Flickable { id:...

Can't use DropShadow in Column?

qt,qml,qtquick2
I was developing a small application using QML, and i need a small drop shadow on the text component, to make it more readable, but when I add the DropShadow to the Label in the Column, it throws an error: "QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn...

Undefined element when tab is not active

qt,qml,qtquick2
When I try to access a son of a Tab element, if it is not active QML throws an error saying is undefined. main.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.0 ApplicationWindow { TabView { Tab { id: mytab1 } Tab { id: myTab2 Rectangle { //(...) }...

Saving images read with glReadPixels where alpha value is not one

qt,opengl,qml,qtquick2
Please look at this image: On the left, there is an image saved using glReadPixels. On the right, the corresponding (correct) rendering: the colors are distorted where their alpha value is less than one. The surface is managed by QtQuick. With glGetInteger I found out there are 8 bits for...

QtQuick2 - QML - create infinite moving line animation

javascript,animation,qml,infinite-scroll,qtquick2
Does anyone know how to implement linear animation, for example like in progress bars, where few of lines moving infinite in the bar from left to right or any other way? I'm going to use only QtQuick2 primitives and without any additional C++ components, glad to see any answers that...

How to access the QML object inside the Loader's sourceComponent?

qt,qml,qtquick2
I may need to read or write to some of the properties of the Loader's sourceComponent from some outside function. What is the way to access the property x of the object inside this Loader's sourceComponent? import QtQuick 2.0 Item { width: 200; height: 200 Loader { anchors.fill: parent sourceComponent:...

QML nested properties - Cannot assign to non-existent property

qt,qml,qt5,qt-quick,qtquick2
I am trying to do nested properties like 'font.family' or 'anchors.fill', but I cannot initialize them in normal way because it prints 'Cannot assign to non-existent property'. Instead I am forced to use Component.onCompleted method. What's wrong? MyButtonStyling.qml: import QtQml 2.1 QtObject { property QtObject background: QtObject { property color...

Is there any QML window UI fully constructed signal?

qt,qml,qtquick2
I've found this, but it is only about QWidget based project. What about ApplicationWindow components in QML?

How to make QtQuick transparent Toolbar

qml,toolbar,qt-quick,qtquick2
How to make the built-in Quick ToolBar transparent so that only buttons are visible?