qml

QML how to use mouse hover together with styleData.selected

老子叫甜甜 提交于 2019-12-12 20:38:09
问题 I'm trying to build a simple delegate for rows in TableView. I want it to show a border in case hovered with mouse and leave a border in cases it's selected. See code below: Component { id: rowDelegate Item { height: 40 Rectangle { id: rowRectSel anchors.fill: parent color: "grey" radius: 2 opacity: 0.4 border.width: 3; visible: styleData.selected } Rectangle { id: rowRect anchors.fill: parent color: "grey" radius: 2 opacity: 0.4 border.width: 1; visible: !styleData.selected } MouseArea { id:

How to add a custom role to QFileSystemModel

眉间皱痕 提交于 2019-12-12 19:18:18
问题 I would like to add a custom role to a QFileSystemModel (probably to a derived model). I want to use this role to save the check state of a CheckBox which is displayed next to the filename in a custom delegate. How can this be done? 回答1: I have used using the example Qt Quick Controls - File System Browser Example removing the part of the selection. The steps were the following: Add a new role in roleNames : QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE { QHash<int, QByteArray>

How can I create an alias to a property within a Repeater?

二次信任 提交于 2019-12-12 18:29:08
问题 This code: Repeater { id: myImageArr property alias changeSource: imageElement model: 3 Image { id: imageElement } } gives me an error: Invalid alias reference. Unable to find id "imageElement" 回答1: The Image inside the repeater is dynamically created depending on the model, so you can't refer it directly by id. If your model is a fixed value (3), then you can access the Image instance by using Repeater.itemAt(index) function. For example, to create alias to the first Image created by

QT: Hide QML Debugging warning

浪尽此生 提交于 2019-12-12 17:55:07
问题 QML debugging is enabled. Only use this in a safe environment. I'm actually working on a test software in Python for a QtCreator project which need to use the QML Debugging. The python software is running the built project and test it's features. I would like to actually hide that message without disabling the QML debug. Is it possible to do it? 回答1: You can specify DEFINES += QT_QML_DEBUG_NO_WARNING in the .pro file to disable the warning. 来源: https://stackoverflow.com/questions/37996105/qt

Custom attached properties in QML

巧了我就是萌 提交于 2019-12-12 17:54:28
问题 I'm creating a custom QML component (a specialization of ListView that allows multiple selection). I'd like to provide attached properties to objects provided to my component. I see how to create attached properties using C++. However, I cannot find information on adding custom properties in pure QML. Is this possible using QML? 回答1: Is this possible using QML? No. 回答2: There is an alternative, easy and clean way to this in QML - just use an adapter object that implements the desired

QML: Resize CheckBox

為{幸葍}努か 提交于 2019-12-12 17:21:53
问题 I have ListView with my own delegate. import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 ItemDelegate { height: 40 Row { spacing: 10 anchors.verticalCenter: parent.verticalCenter CheckBox { } } } The problem is that check boxes does not resize despite ItemDelegate's height. I get this for height = 40: I get this for height = 10: I've tried playing with CheckBox'es width and height values - did not help. Is it possible to make it smaller at all, without customizing it?

Gradient for chunks in QProgressBar

落花浮王杯 提交于 2019-12-12 16:25:34
问题 Is it possible to set a common gradient for all QProgressBar chunks? If use something like this: QProgressBar::chunk:horizontal { background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 green, stop: 1 white); margin-right: 2px; width: 10px; } the result will be http://labs.trolltech.com/blogs/wp-content/uploads/2007/06/progressbar_righttext.png but I want to obtain a one gradient, stretched to all chunks. Like this: http://labs.trolltech.com/blogs/wp-content/uploads/2007/06

QQuickView: handling mouse events in C++

不打扰是莪最后的温柔 提交于 2019-12-12 15:18:10
问题 I render my 3d model under qml controls using QQuickView::beforeRendering event. I want to do my mouse events handling in C++ if user clicks outside any of qml controls/ How can I found out in QQuickView::mousePressEvent that mouse is pressed outside qml controls? 回答1: I think it's easier to do it with a custom QQuickItem , because doing it with a custom QQuickView apparently means that you get the events before they reach any of the items. Here's an example: #include <QtQuick> class MyItem :

Difference in QML between Window and Item in parent-children relationship

醉酒当歌 提交于 2019-12-12 15:15:38
问题 I'm wondering why for Item this works: Item { id: root width: 640 height: 480 MouseArea { anchors.fill: (root or parent. It doesn't matter) onClicked: console.log("clicked") } } But for Window it doesn't. Only anchoring by parent will work, but for anchoring by id it will fail. 回答1: According to the documentation, anchors.fill requires the argument either to be or to identify an Item -derived object. From here you can follow the inheritance chain of Window and see that it is not actually an

Expose QAbstractListModel element properties to QML in Qt 5.0

十年热恋 提交于 2019-12-12 15:07:34
问题 I've been loosely following the article on Christophe Dumez's blog to get a custom QAbstractListModel class to expose the data to a QML (QtQuick2) interface (QtQuick2ApplicationViewer). However, since I'm using Qt 5.0.0 (and MSVC2012), there are some parts of his article that don't apply. For example, the ListModel constructor no longer has to call setRoleNames() , because setRoleNames() has been depreciated in Qt 5. ListModel::ListModel(ListItem* prototype, QObject *parent) :