qtquick2

QML - MouseArea/MouseEvent issue

混江龙づ霸主 提交于 2019-12-22 11:10:24
问题 The following piece of code generates a white rectangle containing a red rectangle and a grey rectangle. Every rectangle has an associated MouseArea. The grey rectangle becomes blue when the mouse is clicked inside it. The red rectangle prints a console message when the mouse cursor enters inside it and another message when the released signal is emitted. I would like to: press and hold the mouse button inside the grey rectangle (becoming blue) move the cursor outside the grey/blue rectangle

Adding Items to a layout of a custom component

天涯浪子 提交于 2019-12-22 08:36:22
问题 I have a custom Footer Component which I would like to reuse in different place in my QML App: Rectangle { color: "gold" height: 50 anchors { bottom: parent.bottom left: parent.left right: parent.right } RowLayout { anchors.fill: parent anchors.margins: 10 Button { text: "quit" } } } The use of this is easy: Window { visible: true Footer { } } But now I would like to add a "ButtonA" to the RowLayout of my Footer in one view and a "ButtonB" in another view. How can I achieve that? 回答1: See

FileDialog in QTQuick (QML): Save file under given name

社会主义新天地 提交于 2019-12-22 04:29:12
问题 We're building a Qt Quick app, that must be able to save a file under a given name . In the FileDialog component you can only set a directory. This is not very user-friendly, since you don't want to type in a filename by hand every time you download a file. So far we tried different things FileDialog from QtQuick.Dialogs: filename cannot be set Native dialog via QPlatformFileDialogHelper (naughty private c++ hack): filename cannot be set on Linux (Gnome) Native dialog via static QFileDialog:

QML screen orientation lock

时光怂恿深爱的人放手 提交于 2019-12-22 04:27:14
问题 I need to lock the screen to a specific orientation for an android app that I'm making. is there a way to do that in QML? Google didn't get me any answers. I am using Qt 5.2. 回答1: You can basically use the Screen.orientation property for reading only. See the following example for details: http://qt-project.org/doc/qt-5/qtquick-window-screeninfo-qml.html The proper way as of today is to use the Android manifest file for this as done by the Qt Android developer at Digia for his QtHangMan game

Display several roles in one column of TableView

我与影子孤独终老i 提交于 2019-12-21 21:38:22
问题 I have a SQLite 3 database with 4 columns and QML code with TableView that displays it: TableView { id: table ... TableViewColumn { role: "name" width: 275 } TableViewColumn { role: "surname" width: 300 } TableViewColumn { role: "phone" width: 575 } TableViewColumn { role: "ip_address" width: 525 } model: abonents } It works fine, but I need to display the first two roles, name and surname , as a unique column in TableView . Here is the code for my model and the main . abonentstable.h:

How to assign SQL query output model from Qt to QML's TableView?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 20:57:57
问题 From C++ (Qt): int main(int argc, char *argv[]) { QApplication app(argc, argv); /* * I have omitted the code about connection with the database and all for ease of * viewing the code. */ // My own function for filling in the data in the `QSqlQueryModel` QSqlQueryModel* model = new QSqlQueryModel; QString binid = "B1"; QString query = "SELECT t1.BinId, t1.PartitionId, t2.UnitId, t2.ItemCount FROM Bin_Partitions AS t1 " "INNER JOIN Partition_Units AS t2 ON t1.PartitionId = t2.PartitionId "

QML applications and security - is there any?

南笙酒味 提交于 2019-12-21 20:15:02
问题 I just made a shocking discovery - when deploying QML applications, all the "stock" QML components used in the project are deployed as bare QML files, directly visible in the file system, they are not even tucked away in the application qrc binary as user QML files are. Meaning that anyone can open those human readable files, and write whatever code he needs executed. Also, it is possible to do a fair amount of introspection on QObject derived types, even from QML, you can crawl down the

QML TableView + QAbstractTableModel - how edit model data from QML?

雨燕双飞 提交于 2019-12-21 06:28:36
问题 I have C++ class inherited from QAbstractTableModel with next functions overriden: virtual QHash<int, QByteArray> roleNames() const noexcept override; virtual Qt::ItemFlags flags(const QModelIndex& index) const noexcept override; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const noexcept override; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const noexcept override; virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const

Using c++ enum in QML as string

不问归期 提交于 2019-12-21 04:57:19
问题 What I would like to do is use the below enum in c++: class MyClass : public QQuickItem { Q_OBJECT Q_PROPERTY(MyEnum enumValue READ getEnumValue) public: enum MyEnum{ MyEnumElement = 0 }; Q_ENUM(MyEnum) slots: MyEnum getEnumValue(){ return enumValue; } private: MyEnum enumValue = MyEnumElement; }; In such a way in QML: MyClass { id: myClass } Text { text: "enumValue is: " + myClass.enumValue } That would result in enumValue is MyEnumElement instead of enumValue is 0 which is the case now. The

how to sort QML TableView in QtQuick 2?

£可爱£侵袭症+ 提交于 2019-12-21 03:01:20
问题 I want to implement a sortable TableView with custom roles with Qt 5.1. But I don't know what to do more to make it sorted when user clicked on header. in my Qt .pro file, I added: !android: !ios: !blackberry: qtHaveModule(widgets): QT += widgets in main.cpp, I used QtWidgets/QApplication as global app instance, and used qmlRegisterType for my new model class(see below): qmlRegisterType<PositionModel>("MyDataModule", 1, 0, "PositionModel"); PositionModel is declared following: class