qtquick2

HTML formatting in QML Text

こ雲淡風輕ζ 提交于 2020-01-01 08:47:06
问题 I have a part of HTML code, which displays small table. In browser it looks like in the picture: But when I want to display it in Text QML (which, according to the documentation, should support HTML), I see: (Orange rectangle is a part of rectangle, which is parent of mytext ) Text { id: mytext anchors.fill: parent text: "<div><table border='1'><caption><h4>Test stats</h4>"+ "</caption><tr bgcolor='#9acd32'><th/><th>Number1</th><th>Number2</th></tr> <tr><th>Line1</th>"+ "<td> 0 </td> <td> 1 <

Access Listview currentIndex from Delegate

*爱你&永不变心* 提交于 2019-12-31 18:00:43
问题 I have a QML ListView where the delegate loads it's component from another file. When clicking on an delegate item, I want to update ListView . CurrentIndex and highlight the selected item. It works, when I explicitly set the id of the ListView . However since I want to use the delegate's Component also for other ListView s, I'm stuggeling to find a generic way how to access ListView.currentIndex from within a delegate Component . Here is the Code: main.qml import QtQuick 2.4 import QtQuick

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

随声附和 提交于 2019-12-31 00:36:26
问题 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 nothing is printed when I destroy qobj . 回答1: In the general case, you can connect to signals emitted from a C++ object using a Connections element: Connections

Android back button press doesn't trigger keys.onreleased qml

烂漫一生 提交于 2019-12-30 18:57:31
问题 I am creating a program in Qt5.3 and Qtquick2.1. I am trying to capture back button press on android in my code using Keys.onReleased. But that event is not getting triggered. Also I have set the item focus to true. But still no success. Here is the code sample import QtQuick 2.1 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 Rectangle { id: main2 focus: true width: Screen.Width height: Screen.Height Keys.enabled: true Keys

Android back button press doesn't trigger keys.onreleased qml

核能气质少年 提交于 2019-12-30 18:57:06
问题 I am creating a program in Qt5.3 and Qtquick2.1. I am trying to capture back button press on android in my code using Keys.onReleased. But that event is not getting triggered. Also I have set the item focus to true. But still no success. Here is the code sample import QtQuick 2.1 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 Rectangle { id: main2 focus: true width: Screen.Width height: Screen.Height Keys.enabled: true Keys

Prevent “inherited” signal handlers from executing

泄露秘密 提交于 2019-12-30 10:42:43
问题 Defining a signal handler in a "base" component is pretty nifty when that functionality is going to be frequently used by many derived components. However, in QML installing a new handler in a derived component does not replace the original handler, it merely stacks on top of it. As handlers are not really unique per signal, they are merely connections, and you can have multiple connections per signal. One solution is to simply not provide a default handler in the base component, but then you

How to create grouped/nested properties?

人盡茶涼 提交于 2019-12-30 03:23:07
问题 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 pressed: "#CCCCCC" property color enabled: "#666666" property color disabled: "#555555" } } main.qml: import QtQuick 2.0 Item { width: 400

Create QML Element in C++?

独自空忆成欢 提交于 2019-12-30 03:22:06
问题 I have the following problem: I load an initial interface into a QQuickView using a .qml file. I then want to add QML types like an Image or Text to the interface using C++. I know I can manipulate existing elements from C++ but how can I create new types and add them? 回答1: Unfortunately the docs are a bit out-of-date (uses Qt4 api), but If you read section Loading QML Components from C++ here: https://doc.qt.io/qt-4.8/qtbinding.html Then you should have something like (with Qt5 api):

How to make a resizable rectangle in QML?

我与影子孤独终老i 提交于 2019-12-28 12:08:07
问题 I'm looking for a simple way to create a rectangle in a QQuickItem . I want to resize, and drag the borders of this rectangle like this (found at resizable QRubberBand) Has someone an idea? 回答1: There are probably several ways to achieve the desired result. Since I've considered the implementation of a similar Component for a cropping tool software of mine, I'm going to share a toy example which uses part of that code. Differently from the rubber band in the example, my Rectangle is resizable

Complex group animation in QtQuick 2.0

不羁岁月 提交于 2019-12-25 16:56:15
问题 Im trying to animate the top level "cont" rectangle to the right, downscale it, and move it over the right a little bit and the back to left on left swipe. At the same time it will down scale the back rectangle also, It will set the scale size to that of the screen and will place the rectangle flush to the right of the screen. Would anyone be ale to give me some pointers on how I need to do it? Check pictures for reference to what I'm trying to achieve And I forgot to mention how would I