qtquick2

Flow layout with centered content

蹲街弑〆低调 提交于 2019-12-23 09:25:39
问题 I have a row with items which should stack when the window width gets too small for displaying all items in a row, as shown in the following sketch: The Flow component stacks the items but they are not centered but aligned on the left or right side: Flow { Item {} Item {} Item {} Item {} Item {} } Is there a built-in way in QML to make the flow centered? 回答1: Well there is no built-in way but I found a workaround to do it. The idea is simple, since Flow is already an Item it has anchors

How do I show a message box with Qt Quick Controls?

ε祈祈猫儿з 提交于 2019-12-23 06:59:08
问题 What is the equivalent of QMessageBox::information() when one wishes to write a QML application using Qt Quick Controls? 回答1: In Qt 5.2 there is MessageDialog: http://doc.qt.io/qt-5/qml-qtquick-dialogs-messagedialog.html import QtQuick 2.2 import QtQuick.Dialogs 1.1 MessageDialog { id: messageDialog title: "May I have your attention please" text: "It's so cool that you are using Qt Quick." onAccepted: { console.log("And of course you could only agree.") Qt.quit() } Component.onCompleted:

QtQuick2 Can't connect ApplicationWindow closing signal to method (C++ novice)

↘锁芯ラ 提交于 2019-12-23 04:35:27
问题 I'm having trouble binding an "On Close" event for my application written in QtQuick. What I'd like to do is do the standard "confirm exit" method and maybe I'm going about this the wrong way. As I understand it I want something like void MainDriver::onClose(QEvent* event) { if(notSaved) { //prompt save event->ignore(); } else event->accept(); } however it seems QQuickCloseEvent isn't derived from QEvent or I'm including the wrong header (very possible) and I can't find out where it is

StackView: storing components along with their items

馋奶兔 提交于 2019-12-23 03:48:55
问题 Consider the following code: StackView { id: stack } Component { id: componentFooBar FooBar {} } ... stack.push({item: componentFooBar}) In the example above, according to the Qt source and documentation, after componentFooBar is pushed to the stack its inner item ( FooBar ) is loaded and pushed to the top of the inner stack. And if I want to access stack head (either by pop() or get(0) ), I'll get FooBar instance, not its Component . So for Qml StackView there's no invariant like stack.push

“module QtQuick is not installed” error in Release build with windeployqt

一世执手 提交于 2019-12-23 03:08:09
问题 I have a simple Qt 5.11 x64 project, MSVC 2017 compiler, with default build settings created by Qt Creator 4.7. It works fine but when I added windeployqt for copying all Qt dlls in Release build I get error (running from Qt Creator) QQmlApplicationEngine failed to load component qrc:/qml/main.qml:1 module "QtQuick" is not installed QML file has import QtQuick 2.7 .pro QT += quick widgets xml CONFIG += c++11 CONFIG += precompile_header PRECOMPILED_HEADER = stdafx.h CONFIG -= embed_manifest

Qt invoking qml function with custom QObject type

和自甴很熟 提交于 2019-12-23 02:52:24
问题 I want to invoke a qml method from c++ passing as a parameter a custom type. This is my custom type (*Note that all the code I post is not exactly what i'm using, i've extracted the relevant parts, so if you try to compile it is possible that some changes have to be made) Custom.h class Custom : public QObject { Q_OBJECT Q_PROPERTY(QString ssid READ getSSID WRITE setSSID) public: Q_INVOKABLE const QString& getSSID() { return m_ssid; } Q_INVOKABLE void setSSID(const QString& ssid) { m_ssid =

QQuickWindow::grabWindow: scene graph already in use

坚强是说给别人听的谎言 提交于 2019-12-23 02:38:10
问题 I tried the code shown here: How to take ScreenShot Qt/QML On execution I am getting the error written in the title. My main.cpp is: #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickWindow> #include <QImage> #include <QDebug> #include "screenshot.h" #include <QQuickView> #include <QQmlContext> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); const char* drigUi = "DrigUI"; qmlRegisterType <screenCapture> (drigUi, 1, 0, "ScreenShot");

Is it possible to transmit pointer to model from C++ to Qt Quick TableView?

不打扰是莪最后的温柔 提交于 2019-12-23 01:35:06
问题 I have class with QSqlDatabase and with pointer to QSqlTableModel in one class. I use pointer to QSqlTableModel, because initialization of database is going on in constructor and after that I create QSqlTableModel using this database (also in constructor but in heap already). This class is registered type in qml and so I create it in QML. How is it better to point out TableView to the QSqlTableModel pointer of this class? If it is possible. 回答1: It is not entirely clear what you're asking. I

Custom TextEdit, how to hide TextInput when it goes wide

拟墨画扇 提交于 2019-12-23 01:12:48
问题 I've trying to create custom text field using TextInput element (I need it to use validator and custom style). But I can't hide part of TextInput content expanding (see image). I have similar problem with other elements, while it have root item (container) what contains other items, childrens can be seen if they are placed out of container coordinates. How can I make childrens parts hidden if they're out of root container? There is the code, but it's actually just template, I've tried to uze

Custom listModel does not notify the view

家住魔仙堡 提交于 2019-12-22 12:41:37
问题 I have my custom list model where I put data which should be displayed on the QML view. But for some kind of reason the view in QML sometimes is updated normally, sometimes with previous data and sometimes updating is not performed. Here is the function where I fill the model - this function is called from some other thread. void MyScreen::fillListModel() { const QString SEPARATOR = " "; myListModel->resetModel(); for (int i = 0; i < MAX_ROWS; ++i) { QString key = QString::fromUtf16(MyData: