Skip to content

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.1k Topics 77.6k Posts
  • [SOLVED]Global Fontloader

    4
    0 Votes
    4 Posts
    2k Views
    MonomixM
    Thanks for the suggestions! I ended up going with a singleton, in the same way as described here: http://stackoverflow.com/questions/27692914/where-to-put-qt-qml-non-visual-application-components
  • QAbstractItemModel + QML5.5 TreeView

    treeview qabstractitemmo
    2
    0 Votes
    2 Posts
    2k Views
    V
    Here's the code class TreeModel : public QAbstractItemModel { Q_OBJECT public: explicit TreeModel(const QString &data, QObject *parent = 0); ~TreeModel(); enum TreeRoles { TitleRole = Qt::UserRole + 1, SummaryRole }; QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; bool setData(const QModelIndex &index, const QVariant &value, int role); Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; protected: QHash<int, QByteArray> roleNames() const; private: TreeItem *rootItem; }; here's the code of the TreeView TreeView { id: view anchors.fill: parent anchors.margins: 2 * 12 + row.height model: treeModel selection: selectionModel headerVisible: false itemDelegate: Component { id: dragDelegate MouseArea { id: dragArea property bool held: false height: content.height drag.target: held ? content : undefined drag.axis: Drag.YAxis onPressAndHold: held = true onReleased: held = false Rectangle { id: content anchors { horizontalCenter: parent.horizontalCenter verticalCenter: parent.verticalCenter } width: dragArea.width height: 20 Text{ anchors.verticalCenter: parent.verticalCenter text: styleData.value } border.width: 1 border.color: "lightsteelblue" color: dragArea.held ? "lightsteelblue" : "green" Behavior on color { ColorAnimation { duration: 100 } } radius: 2 states: State { when: dragArea.held ParentChange { target: content; parent: root } AnchorChanges { target: content anchors { horizontalCenter: undefined; verticalCenter: undefined } } } } } } TableViewColumn { title: "Name" role: "Title" resizable: true } onClicked: { console.log("clicked", index) } onDoubleClicked: { console.log("double clicked " + index) clickedIndex = index console.log("DoubleClickedIndex " + clickedIndex) textEditRect.visible = true; textEdit.text = fileSystemModel.data(index, "Title") textEditRect.forceActiveFocus() isExpanded(index) ? collapse(index) : expand(index) } }
  • Text height

    4
    0 Votes
    4 Posts
    1k Views
    ?
    This is a bit better as it seems to use contentHeight internally: Rectangle { width: 300 height: 100 anchors.centerIn: parent Text { text: "Äp!" anchors.fill: parent fontSizeMode: Text.VerticalFit font.pixelSize: 1000 } } But still "Hallo!" is not fully scaled up. I think the problem stems from the fact that contentHeight doesn't return the actual bounding box of the rendered text but the sum of the cap height and descender height.
  • [Solved] How do I localize a Qt qmldir plugin?

    localization plugin
    3
    0 Votes
    3 Posts
    3k Views
    I
    I just replied to you in stackoverflow, your solution is right, I copied my answer too: I created a Translator class to organize and load translations, I have a QVariantMap that holds language name and file name, then when I create my Translator I have to provide the source directory since that is a requirement to load translations, my class also takes care of storing in QSettings last language used. Now, to answer your question, you can always translate the exact same way as if it was a regular application, on your project file you will have to add something like this: 1 - List all your possible translations TRANSLATIONS = \ translation_sp.ts \ translation_fr.ts 2 - Run lupdate to generate the actual translation files lupdate project.pro 3 - Run lrelease Translate with linguist and create the actual translations, this will generate translation_sp.qm and translation_fr.qm 4 - Deploy translations with your plugin Once you have the qm files deploy them with your plugin, ideally you could standardize the naming, maybe always using plugin_XX.qm 5 - Load plugin translation in application To do this you will have to know the path to the translation file and the filename, so if your plugin is installed in the Qt default directories and you standardized the translation filenames this should be simple qTranslator.load("plugin_XX.qm", "PATH_TO_TRANSLATION_FILE") app->installTranslator(qtTranslator); I simplified this in my class, here is the source code if you want to take a look https://raw.githubusercontent.com/Iktwo/inventory/master/src/translator.cpp https://raw.githubusercontent.com/Iktwo/inventory/master/src/translator.h And here's how you use it: Translator translator(app.data(), "PATH_TO_TRANSLATION"); translator.addTranslation("SP", "plugin_XX.qm"); engine.rootContext()->setContextProperty("translator", &translator); You can install multiple translators, so it will work for your application and your plugins, when I wrote my class I was not expecting different sources but you can modify so every time you add a translation it will take a 2 letter code for the language, the filename and the path to it. Hope this helps!
  • Invisible buttons are still functioning

    qtqml qtquick differentviews states visibility
    13
    0 Votes
    13 Posts
    10k Views
    p3c0P
    @vishnu I have a right-arrow button on my footer where i am pushing a qml file upon clicking. when it is loaded how to disable this button on the footer? enabled = false on click How can make a check before pushing If that is alread in the stack i don't the push it? 2 ways. var myItem = stackView.push( { item: Qt.resolvedUrl("DetailedView.qml"), destroyOnPop:false } ); //check myItem and store it somewhere if(myItem) { } var myItem = stackView.push( { item: Qt.resolvedUrl("DetailedView.qml"), destroyOnPop:false } ); var comp=stackView.get(myItem.Stack.index); //need the item to get its index and not just Stack.index
  • Get camera size[SOLVED]

    2
    0 Votes
    2 Posts
    498 Views
    Z
    Find sourceRect property in VideoOutput
  • How to create a "cut" shadow behind a rectangle?

    rectangularglow shadow
    2
    0 Votes
    2 Posts
    1k Views
    X
    Will BorderImage work?
  • QML WebView not using username and password parts of https_proxy?

    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    1 Posts
    416 Views
    No one has replied
  • Assigning or changing int property using enum inside QML

    c++ qml enum
    2
    0 Votes
    2 Posts
    1k Views
    S
    Received answer on Stack Overflow. Note: The names of enum values must begin with a capital letter in order to be accessible from QML.
  • How to get visible delegates in a GridView

    gridview listvi
    1
    0 Votes
    1 Posts
    494 Views
    No one has replied
  • 0 Votes
    3 Posts
    2k Views
    S
    I misunderstood meaning of flick gesture so I missed that it was a reported bug although I did a search(for mapgesture). https://bugreports.qt.io/browse/QTBUG-46388 It is fixed in 5.6 but not 5.5. However there is a simple workaround. You have to add a MouseArea to the Map element as shown below : Map { id : map plugin: myPlugin anchors.fill: parent focus: true zoomLevel: 9 gesture.activeGestures: MapGestureArea.PanGesture | MapGestureArea.FlickGesture | MapGestureArea.ZoomGesture gesture.flickDeceleration: 3000 gesture.enabled: true //XXXXXXX Added MouseArea { anchors.fill: parent } //XXXXXXX } Thanks to Alexander for pointing me this.
  • Ministro + Qt 5.5

    ministro 5.5
    5
    0 Votes
    5 Posts
    2k Views
    SGaistS
    Hi, @privet it might take a bit of patience, july is generally a month of holidays
  • How to do QML to C++ Property Binding

    5
    0 Votes
    5 Posts
    1k Views
    Propakistanpk.comP
    @RahulY Thanks ! Good Information
  • 0 Votes
    2 Posts
    2k Views
    p3c0P
    @dante I doubt that it will work readily with QML. Javascript support in QML is very restricted as compared to that of Web-Browsers. It lacks of certain objects which are mostly used in these web-browsers supported Javascripts. You can find more info here: http://doc.qt.io/qt-5/qtqml-javascript-hostenvironment.html http://doc.qt.io/qt-5/qtqml-javascript-expressions.html http://doc.qt.io/qt-5/qtqml-javascript-hostenvironment.html#javascript-environment-restrictions You will need to create you own port of it without those restrictions. For eg. here is a blog post for porting-three-js-code-to-canvas3d. Something similar will be needed for the rest too.
  • [SOLVED] Again... "Unable to handle unregistered datatype"

    4
    0 Votes
    4 Posts
    3k Views
    p3c0P
    @topse That's because debug process takes some time and by then the registration is done while it is still busy processing the qml.
  • 0 Votes
    1 Posts
    528 Views
    No one has replied
  • [Solved] Nested QtQuick delegates based on C++ model

    qml qtquick c++ delegates nested
    2
    0 Votes
    2 Posts
    2k Views
    P
    I eventually found a solution/workaround to the problem. I am posting it here if anybody ever needs it. The main issue it seems is wanting to filter the C++ model in QML/JavaScript. Getting elements out of the C++ model into QML seems to be possible as a returning a QVariantMap maps to a JS object in the QML engine. Using this returned object as a model proved not to work directly. This might work with further effort but due to time constraints this approach was abandoned. The new approach was to create a C++ model derived from QAbstractItemModel and reimplementing the necessary functions. This model is essentially a filtering proxy for Model_A and Model_B. The filtering is implemented in QAbstractItemModel::getData() and the elements are exposed through a reimplementation of QAbstractItemModel::roleNames(). For this filtering proxy to change state when the underlying data changes the dataChanged() signals of the underlying models was connected to a method in the proxy model computing the correct index invoking emit dataChanged(index). The QML delegate reuse was then implemented as follows: Rectangle { // some rendering of Model_A Repeater { delegate: Delegate_B{} model: Item{ property var propertyDelegateB: model.propertyDelegateB // mulitple properties possible } } } This worked for my use case as I needed only one element in the model. For multiple elements this approach might not be ideal.
  • QML Button with irregular shapes

    3
    0 Votes
    3 Posts
    2k Views
    PrezesP
    @p3c0 Great idea. Thank you very much !
  • 0 Votes
    4 Posts
    1k Views
    SGaistS
    Glad you found out and thanks for sharing the solution. Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)