qtquick2

Error adding a Menu in QML

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:49:34
问题 I have the following code: import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Controls 1.4 ApplicationWindow { title: qsTr("Hello World!") width: 640 height: 480 visible: true menuBar: MenuBar { id: menuBar } MouseArea { anchors.fill: parent onClicked: { menuBar.menus.addItem("test") } } } When I run it and click, the following message appears: qrc:/main.qml:19: TypeError: Property 'addItem' of object [object Object] is not a function Why is this? EDIT:

qml desktop components scaling

ⅰ亾dé卋堺 提交于 2019-12-11 03:46:51
问题 I want to create a user interface qtquick2 that can be scaled and includes some desktop components. As mentioned in this blogpost the default rendering for qml/qtquick2 should use distance fields and not native text rendering. I tried to scale qt quick controls. The result is rather disappointing. I was testing on ubuntu 64 and qt-5.1.1. The text on the controls is looking bad but all text in standard qml elements (Text/TextEdit) is looking good when scaled. This leads me to think that native

Qt QML Canvas requestPaint does not repaint immediately the scene

爱⌒轻易说出口 提交于 2019-12-11 03:39:33
问题 I'm trying to adapt the Html JS library Char.js to QML QtQuick 2.4. The library have a function to animate the scene. Everything works great if I don't animate it (eg animate with only 1 step of animation). When the animation is used, the canvas freeze until the animation is finished, and then the scene is redraw. Here is the animationLoop function: animationLoop = helpers.animationLoop = function(callback,totalSteps,easingString,onProgress,onComplete,chartInstance){ var currentStep = 0,

`Screen.pixelDensity` equals 0 in non-visual components

半城伤御伤魂 提交于 2019-12-11 03:28:34
问题 I want to use Screen.pixelDensity in QML to calculate the size of my visual components. In order to keep an element's properties in one place (there are a couple of them) I created a container object: import QtQuick 2.0 Item { readonly property double constantValue: 100 * Screen.pixelDensity property double first property double second: first + constantValue // and so on Component.onCompleted: console.log(Screen.pixelDensity) // (1) } When the object is initialized, the statement (1) reports

Expose 2D C++ Game Board to QML using QAbstractItemModel

这一生的挚爱 提交于 2019-12-11 02:09:22
问题 I'm writing a simple Snake game with a game board model in C++ holding a two-dimensional vector of states ( std::vector<std::vector<board::state>> ). Now I want to expose this board to QML so that it's basically some sort of grid/chess board with access to the states of the model. I've read up a lot on this topic, but still wasn't able to understand the mechanics enough to solve my problem. Applying the docs, tutorials and blog entries to my problem is my hurdle here. I subclassed

How to use float in a QML spinbox

旧城冷巷雨未停 提交于 2019-12-11 02:03:06
问题 I use a QML Spinbox but I have trouble to use floats in it. If I write something like value: 5.0 , it will be displayed as 5 , so as an int instead of a float. Do you have any idea of how to proceed ? Thanks a lot and have a good day ! 回答1: You can create a Spinbox with custom texts DoubleSpinBox.qml import QtQuick 2.0 import QtQuick.Controls 2.1 Item { property int decimals: 2 property real realValue: 0.0 property real realFrom: 0.0 property real realTo: 100.0 property real realStepSize: 1.0

Open and close additional window (QML)

旧城冷巷雨未停 提交于 2019-12-11 02:01:47
问题 Currently I have a window openning in the following way: property variant win Button { id: testButton MouseArea { onClicked: { var component = Qt.createComponent("test.qml"); win = component.createObject(testButton); win.show(); } } } Is it ok to create a window like this or there is a better way to do it (from QML, not from C++)? When I close this additional window (just by clicking "x" button), I want to connect it to another event (for example, changing color of the button). How to do it?

Undefined element when tab is not active

痴心易碎 提交于 2019-12-11 01:59:39
问题 When I try to access a son of a Tab element, if it is not active QML throws an error saying is undefined . main.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.0 ApplicationWindow { TabView { Tab { id: mytab1 } Tab { id: myTab2 Rectangle { //(...) } } } Connections { target: eventManager onData: { var scene = myTab2.children[0]; console.log(scene); } } } So, if myTab2 is active, I can see in the console QQuickItem_QML_15(0x27f1e2e0) . If myTab2 is not active, then

“Bind” two QML CheckBoxes together, ensuring their states are always identical

最后都变了- 提交于 2019-12-11 00:57:46
问题 I'd like to create two checkboxes on different pages of a GUI such that they are semantically the "same" checkbox -- same label, same effect. (Having them on both pages is just for the user's convenience.) This requires "binding" two CheckBox QML elements together such that the state of one is always reflected by the other, and vice-versa. This is equivalent to what's being asked here, except I'm using QML/JS instead of JS/JQuery. I thought that a naive implementation of binding the checked

QML Keyboard Shortcuts are interfering with Key OnPressed Events

▼魔方 西西 提交于 2019-12-10 21:38:38
问题 I'm having an issue with my QML program. In the top-level main.qml file, I have some keyboard Shortcuts like so: Shortcut { sequence: "Up" onActivated: { // yadda yadda } } In another file, I have several Keys.onPressed calls like this: Keys.onPressed: { if (event.key == Qt.Key_Up) { // yadda yadda } } Apparently, the Shortcuts are interfering with the OnPressed calls. When I comment out the Shortcuts, the OnPressed's work fine. But when they're both active, it seems the Shortcut intercepts