Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.0k Topics 77.4k Posts
  • [SOLVED] PyQt5 connect to QML (Question)

    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • GridLayout and screen rotation

    5
    0 Votes
    5 Posts
    2k Views
    D
    Thanks for the great explanation! I ended up using the GridView with the ObjectModel. Seems to work as I expected. Thanks again.
  • Change a QML state from a model role

    3
    0 Votes
    3 Posts
    2k Views
    O
    Hello and welcome to devnet, yes it is possible to pass a string from Cpp to QML using a Model(It also works without a model), let me provide you an example: main.cpp @#include "Model.h" #include <QDeclarativeContext> #include <QDeclarativeView> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); QDeclarativeView *view = new QDeclarativeView; QDeclarativeContext *context = view->rootContext(); QObject *object = (QObject *)view->rootObject(); Model *model = new Model(0); view->setSource(QUrl("qrc:/qml/qmlview.qml")); context->setContextProperty("listModel", model); view->show(); return a.exec&#40;&#41;; }@ model.h @#ifndef MODEL_H #define MODEL_H #include <QModelIndex> class Model : public QAbstractListModel { Q_OBJECT public: Model(QObject *parent); ~Model(); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; enum Roles { NameRole = Qt::UserRole }; QHash<int, QByteArray> roleNames() const { QHash<int ,QByteArray> roles; roles[NameRole] = "name"; return roles; } }; #endif // MODEL_H@ model.cpp @#include "Model.h" Model::Model(QObject *parent) :QAbstractListModel(parent) { } int Model::rowCount(const QModelIndex &parent) const { return 4; } int Model::columnCount(const QModelIndex &parent) const { return 1; } QVariant Model::data(const QModelIndex &index, int role) const { if(role == NameRole) { return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); } return QVariant(); } Model::~Model(){ }@ src.qrc @<RCC> <qresource prefix="/qml"> <file>qmlview.qml</file> <file>image.bmp</file> </qresource> </RCC>@ qmlview.qml @import QtQuick 1.1 Rectangle { id: main height: 200; width: 200 GridView { id: view width: 200; height: 200 model: listModel delegate: Rectangle { height: 25 width: 100 Text { text: name } } } }@ That way i pass 4 Strings to my QML file. The important part here is the data function, it returns the variable(QVariant) depending on the current index and role. There is also an easier way to provide a string from Cpp to QML. We will need an aditional setContextProperty in our main.cpp: @context->setContextProperty("myOwnCppText", QVariant("Yes it works"));@ Let us just create a text in our QML-File: @ Text { width: 300; height: 20 text: myOwnCppText }@ It will display the text we pass from Cpp to QML. Another method would be to use the rootObject() and its setProperty() function. That way you just pass the name of the property as the first parameter and the value as the second one. Our QML-File should have included a property string variable, with the name of our first parameter: @ property string anotherTextFromCpp: "" Text { width: 300; height: 20 text: anotherTextFromCpp }@ A third method would be to invoke a QML method from Cpp and pass the text as a string as a parameter. Then we can handle the text in our function however we want/need.
  • Could not load qml file on Deployment on Android Device

    2
    0 Votes
    2 Posts
    1k Views
    J
    You can try adding the import path explicitely with QQmlEngine::addImportPath(assets:/...). Just to be sure.
  • SetMainQmlFile it doesn't work

    8
    0 Votes
    8 Posts
    3k Views
    JKSHJ
    Hi freddy311082, It looks like other people are struggling with this issue too: https://bugreports.qt-project.org/browse/QTCREATORBUG-11277 It will be fixed for Qt Creator 3.1. In the meantime, you can edit the generated code. Open qtquick2controlsapplicationviewer.cpp and change this line: @ void QtQuick2ControlsApplicationViewer::setMainQmlFile(const QString &file) { ... // component.loadUrl(QUrl::fromLocalFile(d->mainQmlFile)); component.loadUrl(QUrl(file)); ... } @
  • [Solved]Hide Title bar in Qt Quick Application

    4
    0 Votes
    4 Posts
    10k Views
    O
    You're welcome. I'm glad that i could help you. Please add [solved] to the title of this thread so everyone else can see that the problem is solved/a solution was providet.
  • Define the page size for QtQuick designer

    4
    0 Votes
    4 Posts
    1k Views
    O
    You're welcome. Have you tried it with null? @width: mwSystem.width == null? 1 : mwSystem.width height: mwSystem.height == null ? 1 : mwSystem.width@ Okay, im glad that you found a solution.
  • Font.pixelSize Based On Text Width: Binding Loop

    1
    0 Votes
    1 Posts
    570 Views
    No one has replied
  • Problem getting C++ class exposed to QML

    6
    0 Votes
    6 Posts
    7k Views
    G
    I have done @Q_DECLARE_METATYPE(Model::StructuralElement*)@ I can't do @Q_DECLARE_METATYPE(Model::StructuralElement)@ because it's an abstract class... @1>c:\qt\qt5.2.1\5.2.1\msvc2012_64\include\qtcore\qmetatype.h(719): error C2259: 'Model::StructuralElement' : cannot instantiate abstract class @ I never pass a StructuralElement through (obviously, it's abstract!), I return a pointer to one of these from a Q_PROPERTY like so: @Q_PROPERTY(StructuralElement* parent READ Parent WRITE Reparent NOTIFY ParentChanged)@ I can use that property no problems in C++, but I can't call it from QML or I get the print out mentioned above. Perhaps I am supposed to do this instead: @qmlRegisterType<StructuralElement*>() @ Nope, that doesn't compile. How's it supposed to work?
  • How can I force a repaint of the screen ?

    4
    0 Votes
    4 Posts
    2k Views
    O
    Hmm okay, in that case i would go for the signal-slot connection.
  • How to disable PathView looping?

    2
    0 Votes
    2 Posts
    724 Views
    O
    I don't think that it is possible, yet.
  • GroupBox styling

    8
    0 Votes
    8 Posts
    20k Views
    A
    sfabry thank you for the example. vitala you can add Style into you GroupBox without adding new style file. Here is what I've made from sfabry's example. main.qml @ import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Controls.Private 1.0 ApplicationWindow { title: qsTr("Hello World") width: 640 height: 480 GroupBox { anchors.centerIn: parent style: Style { property Component panel: Rectangle { Text { anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.top text: control.title color: control.enabled ? "red" : "gray" renderType: Text.NativeRendering font.italic: !control.enabled font.weight: Font.Bold font.pointSize: 18 } } } title: qsTr("The Title in Red") enabled: true Column { spacing: 2 CheckBox { text: qsTr("Update system") } CheckBox { text: qsTr("Update applications") } CheckBox { text: qsTr("Update documentation") } } } } @
  • Miss cell in Grid

    8
    0 Votes
    8 Posts
    2k Views
    N
    [quote author="SteveG" date="1394893950"]To my knowledge, Grid ignores objects with visible: false and doesn't leave an empty cell. That's why I suggested GridView. I hope this helps.[/quote] Ok. I will use GridView. Thank you! :)
  • How to access c++ vector in QML

    2
    0 Votes
    2 Posts
    4k Views
    p3c0P
    AFAIK, you can't use vector of objects in QML. (not sure though :)) The best possbile way would be to use a QVariantMap to store object properties as Map elements. See "this":http://qt-project.org/doc/qt-5.0/qtqml/qtqml-cppintegration-data.html#qvariantlist-and-qvariantmap-to-javascript-array-and-object for how to access QVariantMap in QML.
  • Custom QuickItems not visual in designer

    1
    0 Votes
    1 Posts
    515 Views
    No one has replied
  • How Can i use QWindow's setIcon public method in Window type in Qml?

    1
    0 Votes
    1 Posts
    571 Views
    No one has replied
  • Qt 5, QML 2.0 and transparent borderless window incompatibility

    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • How can I scale my WebView content size?

    7
    0 Votes
    7 Posts
    5k Views
    T
    I solve my problem using experimental.userAgent property @ import QtWebKit.experimental 1.0 WebView { anchoranchors.fill: parent experimental.userAgent: "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25" } @
  • Share repo between win and linux?

    1
    0 Votes
    1 Posts
    555 Views
    No one has replied
  • Accessing properties of button style from button

    8
    0 Votes
    8 Posts
    2k Views
    O
    You're welcome, i'm sorry that i couldn't help you out more. style: and background: are properties, so the problem might be the accessing of a component which is the value of these properties?