How can I set properties of external QML which is loaded via Loader
I have a QML loaded via Loader & registered as .rcc file via registerResource(), I want to change some properties, ex. name : "LoadedQml". How can I do it?
do you know?
how many words do you know
See also questions close to this topic
-
How to assign two or more values to a QMap Variable in Qt
I am getting confused of how to store the values assigned from 3 different functions and storing them in a single map variable
QMap<QString,QString> TrainMap = nullptr; if(......) ( TrainMap = PrevDayTrainMap(); TrainMap = NextDayTrainMap(); TrainMap = CurrentDayTrainMap(); }
The PrevDayTrainMap,NextDayTrainMap & CurrentDayTrainMap returns a set of values with Date and the TrainIdName.I need to store all the values from prevday,currentday and nextday in the TrainMap but it stores only the currentday values to the TrainMap as it is assigned at the last.I am not sure what to do so that it doesn't overwrite.If I should merge what is the way to do it?
-
When to use qmake eval?
https://doc.qt.io/qt-5/qmake-test-function-reference.html
eval(string) Evaluates the contents of the string using qmake syntax rules and returns true. Definitions and assignments can be used in the string to modify the values of existing variables or create new definitions. For example: eval(TARGET = myapp) { message($$TARGET) }
I wondering when/why that should be used? Can't we just use
TARGET = myapp
directly? -
How to use qmake.conf?
https://doc.qt.io/qt-5/qmake-environment-reference.html mentions
qmake.conf
, but how can I use it? What is the format? What would be one use case for it? -
How to disable vsync right way in QML
I've found only one way to disable vsync in QML that works, but animations were too fast
QSurfaceFormat format; format.setSwapInterval(0); QSurfaceFormat::setDefaultFormat(format);
I think, i found the way to disable vsyc using environment variables, but i don't remember how.
With vsync the speed of animations is normal, as expected. But with a mouse dragging there is a laaaarge latancy: https://youtu.be/xSpdCfFBSyo
Without vsync the speed is too fast, idk why. But with a mouse dragging it works like i wanted - with no latancy: https://youtu.be/i5xuOztnrhs
-
How to add the UIA ExpandCollapse pattern in Qml
I'm using http://accessibilityinsights.io/ to make sure my QML application passes Microsoft requirements for accessibility.
There's only one error that I couldn't resolve.
Qml ComboBoxes don't have the ExpandCollapse pattern.
Code to reproduce:
ComboBox { model: ["First", "Second", "Third"] }
Accessibility Insights says "An element of the given ControlType must support the ExpandCollapse pattern. Section 508 502.3.10
And "How to fix": 1. Make sure the element has the appropriate ControlType property for its function. 2. If the current ControlType is correct, modify the element to support the ExpandCollapse pattern.
StackOverflow couldn't help me. Google couldn't help me (I tried looking everywhere...)
So I went to Qt's source code.
I found this: qt-everywhere-src-6.2.1\qtbase\src\plugins\platforms\windows\uiautomation\qwindowsuiamainprovider.cpp
And here's the part that was interesting:
case UIA_ExpandCollapsePatternId: // Menu items with submenus. if (accessible->role() == QAccessible::MenuItem && accessible->childCount() > 0 && accessible->child(0)->role() == QAccessible::PopupMenu) { *pRetVal = new QWindowsUiaExpandCollapseProvider(id()); }
Which means that there must be a MenuItem object (the qml combobox doesn't have that), nor a child that's a PopupMenu.
So I checked, and the ExpandCollapse pattern works fine in a menu (from QWidgets), but not in qml.
I couldn't change the combobox's role (Accessible.MenuItem), it doesn't register for some reason (perhaps because of the c++ backend)
I tried "hacking" this in qml, to see if it could work, with this:
MenuItem { text: "test" Rectangle { Accessible.role: Accessible.PopupMenu visible:false // to make the state "collapsed" by default. } }
And ... it works. I have the pattern. But obviously this isn't a combobox (not by name, not for accessibility, and not for functionality).
So here's my question: is there a way to maybe have my custom combobox to have the combobox Accessible.role, while having this structure (Accessible.MenuItem + Accessible.PopupMenu) to make qwindowsuiamainprovider.cpp add the ExpandCollapse pattern?
Or is the only way to find a way to either change qwindowsuiamainprovider.cpp, or override it or something?
I couldn't find any way to change it without recompiling Qt myself with this change (I would also have to check the license if I'm allowed to do it...)
-
Get mouse x & y in nested MouseArea with hoverEnabled
I made a simplified MapImage component which allows to zoom and pan an image with the mouse. This component uses Flickable and MouseArea components. The MapImage component just handles image display, zooming and panning. I want to use another MouseArea in the MapImage instance in main.qml (to be able to place objects using a Canvas but this is not important here). This is not the job of MapImage, so I really need this second MouseArea component.
I need to set the hoverEnabled property to true because I need onPositionChanged and others events... But this property seems to cause problems with mouseX and mouseY values taken from my
updateFlickable
function. When I'm zooming with the mouse wheel, zoom does not occur at the mouse position...I've made a minimal example available here or in a gist.
Any hint to solve this?
main.qml
import QtQml.Models 2.11 import QtQuick 2.11 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.11 MapImage { id: map height: 600 width: 800 imageSource: "https://images.unsplash.com/photo-1651634099253-720df02a0d50" MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton hoverEnabled: true // this is required to use onPositionChanged preventStealing: false onPressed: { // needed for flickable mouse.accepted = false; } onPositionChanged: { // do something. } } }
MapImage.qml
import QtQuick 2.11 Item { id: root property alias imageSource: image.source Flickable { id: flickable anchors.fill: parent contentWidth: props.originalImageWidth contentHeight: props.originalImageHeight Image { id: image fillMode: Image.PreserveAspectFit onStatusChanged: { if (status === Image.Ready) { props.originalImageWidth = sourceSize.width; props.originalImageHeight = sourceSize.height; props.changeCurrentScale(1); } } // define the image display size width: flickable.contentWidth; height: flickable.contentHeight; MouseArea { id: mouseArea anchors.fill: parent acceptedButtons: Qt.LeftButton hoverEnabled: true onWheel: { wheel.accepted = false; props.changeCurrentScale(wheel.angleDelta.y); } } } QtObject { id: props // original image size property int originalImageWidth property int originalImageHeight property real scaleStep: 0.2 property real currentScale: 0.1 onCurrentScaleChanged: updateFlickable(currentScale); function updateFlickable(scale) { console.log(mouseArea.mouseX, mouseArea.mouseY); // <------ I am no longer able to get mouse x and y coordinates flickable.resizeContent(originalImageWidth * scale, originalImageHeight * scale, Qt.point(mouseArea.mouseX, mouseArea.mouseY)); flickable.returnToBounds(); } function changeCurrentScale(wheelDelta) { if (wheelDelta > 0) currentScale = currentScale * (1 + scaleStep); else currentScale = currentScale / (1 + scaleStep); } } } }