Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.1k Topics 77.6k Posts
  • Show popup outside window in qml

    Unsolved popup qml
    2
    0 Votes
    2 Posts
    1k Views
    B
    @niks_entire I asked something similar recently. Basically this is how popups, dialogs etc. work in QML. If you want a separate window, then you basically have to use the Window component and implement it yourself. This is what I did recently when I needed a dialog that was separate from the main window. For a popup menu, I wonder whether you could use PopupMenu inside your separate Window (i.e fill theWindow with the popup) to benefit from at least some of the built-in functionality.
  • ListView Section

    Unsolved
    4
    0 Votes
    4 Posts
    460 Views
    ?
    I don't know how to access listview model current image property in section area. We can use multiple property in section ? ListView { id: fixtureList width: parent.width height: parent.height - (header.height + tabBar.height) * dp anchors.top: header.bottom anchors.left: parent.left focus: true clip: true model: ListModel{} delegate: Rectangle { id: dataModel height: 100 * dp Text { id: matchStartTime text: "22:04" anchors.left: parent.left anchors.leftMargin: 5 anchors.top: parent.top anchors.topMargin: 5 } } section { property: "name" criteria: ViewSection.FullString delegate: Rectangle { color: "#d2d4c7" width: parent.width height: 50 * dp Text { text: section anchors.left: parent.left anchors.leftMargin: 15 anchors.top: parent.top anchors.topMargin: 5 font.pixelSize: 15 font.family: fontRegular.name } } } }
  • QStorageInfo in read only rootfs

    Unsolved
    1
    0 Votes
    1 Posts
    131 Views
    No one has replied
  • ListView: position CurrentItem as last visible element?

    Unsolved qml listview currentindex
    1
    0 Votes
    1 Posts
    593 Views
    No one has replied
  • QML ListView's positionViewAtIndex incorrectly modifies currentIndex

    Unsolved qml listview
    2
    0 Votes
    2 Posts
    1k Views
    M
    Just an update, not sure if this is the reason for the behavior described above, but I had two ListView properties set to values, which could be contributing to this: preferredHighlightBegin: Math.floor(width/2) preferredHighlightEnd: Math.floor(width/2 + 1) I noticed that to trigger the issue I had to resize the window, so it makes sense to me that once I resized the window the preferredHighlight area would be not in the center, while positionViewAtIndex would position the item exactly at the center, which would then cause currentIndex to be updated to the next item.
  • Reflection of scene bounding box edges on metal surfaces

    Unsolved
    1
    0 Votes
    1 Posts
    145 Views
    No one has replied
  • 0 Votes
    1 Posts
    380 Views
    No one has replied
  • HorizontalHeaderView not reading data from headerData

    Unsolved
    2
    0 Votes
    2 Posts
    591 Views
    S
    I think I found the reason why it is not working. The Qt docs state this for the model of headerView: If the model is a QAbstractTableModel, then the header will display the model's horizontal headerData(); otherwise, the model's data(). So how do I have to implement data to show the headers? I tried this: QVariant QuestionsProxyModel::data(const QModelIndex &index, int role) const { if(role == Qt::DisplayRole) { switch (index.column()) { case 0: return tr("Id"); case 1: return tr("Question"); case 2: return tr("Answer 1"); case 3: return tr("Answer 2"); case 4: return tr("Answer 3"); case 5: return tr("Answer 4"); case 6: return tr("Correct Answer"); case 7: return tr("Picture"); } } QModelIndex newIndex = mapIndex(index, role); if (role == idRole || role == askedQuestionRole || role == answer1Role || role == answer2Role || role == answer3Role || role == answer4Role || role == correctAnswerRole || role == pictureRole) { return QIdentityProxyModel::data(newIndex, Qt::DisplayRole); } return QIdentityProxyModel::data(newIndex, role); } With the same result as before. The hacky workarround was to set an own model on headerView with the names: HorizontalHeaderView { id: horizontalHeaderView syncView: tableView anchors.left: tableView.left model: [qsTr("Id"), qsTr("Question"), qsTr("Answer 1"), qsTr( "Answer 2"), qsTr("Answer 3"), qsTr("Answer 4"), qsTr( "Correct Answer"), qsTr("Picture")] }
  • Expose C++ Submodel to QML

    Unsolved
    24
    0 Votes
    24 Posts
    3k Views
    P
    Here is the example: main.cpp #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> #include "mymodel.h" int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QQmlContext *context = engine.rootContext(); myModel *model = new myModel(); context->setContextProperty("myModel", model); const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); } mymodel.h #ifndef MYMODEL_H #define MYMODEL_H #include <QStandardItemModel> #include <QObject> #include <QDebug> #define ROWS 10 #define NESTED 3 #define SUBITEMS 8 class myModel : public QStandardItemModel { Q_OBJECT public: myModel(); void fillModel(); QVariantMap getObject(const QModelIndex &index); QVariantMap getObject(QStandardItem *item); Q_INVOKABLE QVariant getQMLObject(const QModelIndex &index); Q_INVOKABLE void setValue(const QModelIndex &index, int value); enum Roles{ Name=Qt::UserRole+1, Value, Description, QMLObject }; public slots: void updateObject(const QModelIndex &left, const QModelIndex &right, const QVector<int> &roles); private: QHash<int, QByteArray> roleNames; QHash<int,QVector<QPersistentModelIndex>> m_Objects; }; #endif // MYMODEL_H mymodel.cpp #include "mymodel.h" myModel::myModel() { roleNames[Name] = "name"; roleNames[Value] = "value"; roleNames[Description] = "description"; roleNames[QMLObject] = "qmlObject"; setItemRoleNames(roleNames); fillModel(); connect(this, &QAbstractItemModel::dataChanged, this, &myModel::updateObject); } void myModel::fillModel() { for(int i = 0; i < 3; i++){ QStandardItem *item = new QStandardItem(); item->setData("TreeParameter"+QString::number(i+1), Name); item->setData(i, Value); item->setData("Tree item"+QString::number(i+1), Description); item->setData(getObject(item), QMLObject); for(int j = 0; j < 8; j++){ QStandardItem *subItem = new QStandardItem(); subItem->setData("SubItem"+QString::number(j+1), Name); subItem->setData(j, Value); subItem->setData("Nested item"+QString::number(j+1), Description); subItem->setData(getObject(subItem), QMLObject); item->appendRow(subItem); } this->appendRow(item); } for(int i = 3; i < 10; i++){ QStandardItem *item = new QStandardItem(); item->setData("Parameter"+QString::number(i+1), Name); item->setData(i, Value); item->setData("Usual item"+QString::number(i+1), Description); item->setData(getObject(item), QMLObject); this->appendRow(item); } } QVariantMap myModel::getObject(const QModelIndex &index) { return getObject(itemFromIndex(index)); } QVariantMap myModel::getObject(QStandardItem *item) { QVariantMap result; result[roleNames[Name]] = item->data(Name); result[roleNames[Value]] = item->data(Value); result[roleNames[Description]] = item->data(Description); return result; } QVariant myModel::getQMLObject(const QModelIndex &index) { return index.data(QMLObject); } void myModel::setValue(const QModelIndex &index, int value) { setData(index, value, Value); } void myModel::updateObject(const QModelIndex &left, const QModelIndex &right, const QVector<int> &roles) { if(roles[0] == QMLObject) return; QVariantMap obj = left.data(QMLObject).toMap(); obj[roleNames[roles[0]]] = left.data(roles[0]); setData(left, obj, QMLObject); } main.qml import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Layouts 1.12 import QtQuick.Controls 1.4 as QC1 import QtQuick.Controls 2.12 import QtQml.Models 2.11 Window { width: 640 height: 280 visible: true title: qsTr("Hello World") RowLayout{ anchors.fill: parent QC1.TreeView{ id: tree Layout.fillWidth: true; Layout.fillHeight: true; model: myModel selection: ItemSelectionModel{ id:mySelectionModel model: myModel } itemDelegate: ItemDelegate{ Text{ text: styleData.value } MouseArea{ anchors.fill: parent onClicked:{ tree.selection.setCurrentIndex(styleData.index,ItemSelectionModel.SelectCurrent); target.modelItem = myModel.getQMLObject(styleData.index); target.modelIndex = styleData.index; } } } QC1.TableViewColumn{ width: 150 title: "Name" role: "name" } QC1.TableViewColumn{ width: 50 title: "Value" role: "value" delegate: TextEdit{ text: styleData ? styleData.value : ""; Keys.onReturnPressed: { focus = false; myModel.setValue(styleData.index, text); } } } QC1.TableViewColumn{ width: 150 title: "Description" role: "description" } } RowLayout{ id: target Layout.fillWidth: true; property var modelIndex: false property var modelItem: false Rectangle{ implicitHeight: 20 implicitWidth: 65 border.color: "black"; border.width: 1 TextEdit{ id: targetValue anchors.fill: parent horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: target.modelItem ? target.modelItem.value : "NaN" Keys.onReturnPressed: { targetValue.focus = false; if(target.modelIndex) myModel.setValue(target.modelIndex, targetValue.text); } } } TextArea{ id: targetText readOnly: true implicitWidth: 130 wrapMode: Text.Wrap text: target.modelItem ? target.modelItem.name : "Nothing yet" } } } } Guess I'll have to explain it a little bit. When I click an item of the model in TreeView its QMLObject role is sent to target component, where Value is given to TextEdit and Name is given to TextArea along with the QModelIndex of selected item. So when I change the value inside of TextEdit it updates the value in model. The issue here is that if I change the value inside TreeView it won't be updated in TextEdit, because target receives only a copy of QMLObject role through return index.data(QMLObject);. I know about possibility to pass QQmlDMAbstractItemModelData from TreeView to the taget, but I'm trying to bind model item to target directly, this TreeView is only to make this example more clear. Sorry, couldn't think of something smaller, guess I'm too deep in this topic to keep it simple
  • QML Vertical TabBar

    Unsolved
    2
    0 Votes
    2 Posts
    3k Views
    T
    hello , I try it , but in this way , the Flickable feature of tabBar cannot be used in vertical.
  • How to open other QML files in main.qml (error: no such file or directory)

    Solved
    9
    0 Votes
    9 Posts
    6k Views
    F
    @J-Hilk OMG I am such an idiot... 4 hours of Googling... :D Thank you for saving my life! In conclusion of others the original code I've posted is not working only because of this typing laxity.
  • signals and slots in QT Quick , firstqml to cpp and cpp to second qml

    Unsolved
    9
    0 Votes
    9 Posts
    802 Views
    6thC6
    I'd also suggest using the https://wiki.qt.io/New_Signal_Slot_Syntax The old syntax isn't as clean/concise - also doesn't provide you with compile time checks/safeties. If you are like me: you'll break things more often than you want to and letting the compiler do that work instead means you don't have to. Honestly, I'd start with the example projects bundled inside Qt Creator. Or even just a new application based on QtQuick template will get you a QML app started. Then you can use those integration links to do more. The examples apps will get you something basic that starts and you can witness it working, take a copy of and start pulling that apart to understand.
  • Too often called createObject

    Solved
    6
    0 Votes
    6 Posts
    530 Views
    GrecKoG
    @KaNe09 said in Too often called createObject: With Repeater I got a column with modelPath entries and each entry has all my paths. I want a column with each line has one path That's what the code I pasted does, equivalent to what your imperative code did. It creates a Text for each path of your modelPath
  • Getting pixel information under cursor

    Solved
    3
    0 Votes
    3 Posts
    685 Views
    F
    I managed to do the needful using Canvas: Canvas { id: canvas anchors.top: parent.top anchors.topMargin: 0 anchors.left: parent.left anchors.leftMargin: 0 width: 720 height: 720 onPaint: { var ctx = getContext("2d") if (canvas.isImageLoaded(rgb_palette)) { var im = ctx.createImageData(rgb_palette); ctx.drawImage(im, 0, 0) } } Component.onCompleted:loadImage(rgb_palette); onImageLoaded:requestPaint(); MouseArea { id: mouseArea anchors.fill: canvas onClicked: { var ctx = canvas.getContext("2d") var id = ctx.getImageData(mouseArea.mouseX, mouseArea.mouseY, 1, 1) console.log(id.data[0], id.data[1], id.data[2]) } } }
  • qmlscene crashed when hover in at a ScatterSeries point

    Unsolved
    1
    0 Votes
    1 Posts
    186 Views
    No one has replied
  • [SOLVED] Fill GridLayout with Repeater

    8
    0 Votes
    8 Posts
    6k Views
    F
    I know this is a very, very old topic by interweb standards, but the proposed solution didn't work for my situation, nor did anything else I found, so I thought I'd post the (admittedly) kludgey workaround I figured out. I'm using grids as a lightweight sort of table, since trying to do what I need with actual tables ended up requiring hundreds of lines of nonsense and much hoop-jumping (lots of variables; don't ask). I basically want column headers in a GridLayout, with a repeater to generate all of the subsequent rows, like this: [image: b958bdba-88fe-4e4d-87ad-b0ef650fe600.png] I stumbled upon a combination of three things necessary to make it work for me (as of v5.15.1). The repeated content must have: Each row wrapped in an Item component Each cell parented to the GridLayout component Cells within a row listed in reverse column order Not doing any one of those three things breaks the layout for me. Here's a working example, used to generate the screenshot above: import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 ApplicationWindow { id: root width: 300 height: 300 color: "#111" GridLayout { id: grid anchors.centerIn: parent columns: 3 // Column headers are direct children of the GridLayout Label { text: "Red" color: "#eee" } Label { text: "Green" color: "#eee" } Label { text: "Blue" color: "#eee" } // HACK: somewhat kludgey, but grid cells in a repeater must be: // - Wrapped in an Item component // - Parented to the GridLayout component // - In reverse order Repeater { model: 3 Item { Rectangle { parent: grid width: 50 height: 50 color: "blue" } Rectangle { parent: grid width: 50 height: 50 color: "green" } Rectangle { parent: grid width: 50 height: 50 color: "red" } } } } }
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    8 Views
    No one has replied
  • Problem with macdeplayqt and Qt3D

    Unsolved qtquick qt3d renderer macdeployqt qml
    7
    1 Votes
    7 Posts
    1k Views
    SGaistS
    Or you can fix the macdeployqt code and build it to replace your version. That way you benefit from all the file processing done during the deployment process.
  • TableView replacement for TableViewColumn in Qt Quick 2

    Solved
    3
    0 Votes
    3 Posts
    639 Views
    S
    An answer can be found here: https://stackoverflow.com/questions/64403258/tableview-replacement-for-tableviewcolumn-in-qt-quick-2
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    10 Views
    No one has replied