qml

How to mock a QML component

陌路散爱 提交于 2019-12-23 08:46:50
问题 Actually I'm trying to run some test on a QML component which embeds C++ objects. Unfortunately, I'm getting some errors when I execute my tests. The C++ objects aren't recognized by the QML file. That makes also sense as the C++ objects are set in the main.cpp file. My question is: How can I mock an context property for performing QML tests? Or other said, how can I do unit-test with mixing Qt/QML code? 回答1: As I understand you right, you got same problem as I. Some time ago I wrote this

QML - getting the code of a JS function as a string

℡╲_俬逩灬. 提交于 2019-12-23 08:03:01
问题 It seems like it is possible to get the code of a function in JavaScript, and that it is as simple as: function foo() {...} foo.toString() However, doing that in QML gives me a rather uninspiring function () { [code] } So is there a way to get the [code] part as well? I also tried JSON.stringify() but it didn't do any good. 回答1: I'd like to sum up the discussion that took place in the comments, for this can be a good response for future searches. As already stated in the comments, it looks to

Delete children of QML Grid

≡放荡痞女 提交于 2019-12-23 07:57:51
问题 I want to loop through a QML Grid's children and destroy each of them using Javascript. Grid { id: contentGrid spacing: 10 ImageItem { imageSource: "file:/foo.jpeg" } // destroy this ImageItem { imageSource: "file:/bar.jpeg" } // destroy this as well } I tried to do something like this but it's not working so far. for(var i = 0; contentGrid.children.length() < i; i++) { contentGrid.childAt(i).destroy(); } 回答1: You have a number of problems in your attempt above... First, you'll need to

QML How to paint different to grabToImage()

混江龙づ霸主 提交于 2019-12-23 07:57:17
问题 Is there any possible way to make grabToImage() buffer different from what's displayed in GUI? I'm using ChartView without legend in GUI and want to export it to PNG with legend. So I try: chartView.legend.visible = true chartView.update() chartView.grabToImage(function(result) { console.log("grabbed") var path = filename.toString().replace(/^(file:\/{2})/,""); console.log(path + result.saveToFile(path)); chartView.legend.visible = false update(); }); But both those updates happen only after

QML Qt openUrlExternally

一个人想着一个人 提交于 2019-12-23 07:46:30
问题 I've just discovered strange behavior when using this code Qt.openUrlExternally(someurl); I would like to let my users open facebook sharer url, but I cannot use this code, as it does nothing. Tested on S60 5th and Symbian^3 devices (C5, C7, 5230, N8) So please tell me (if you know) 1) Is there any BUG about this component/behavior ? (I searched and didn't found anything) 2) How can i make C++ component to do the same thing ?` (If it is solution) Thanks Edit I found example for creating C++

How can I get a borderless child window to re-scale to current screen in multi-monitor setup?

ぐ巨炮叔叔 提交于 2019-12-23 07:28:51
问题 My app has a main window which creates and opens an instance of a subclass of a QML Window {} using createObject() . This window has its flags: set to be a borderless window (I've added code so that it can be grabbed and dragged around). When I attach a monitor to my laptop and set its font scale factor to 125% (or 150%), when I drag my main window over to the second monitor, you can see it suddenly "snap" to the larger size when it reaches the halfway point. Likewise, when I drag it back to

Qt: Compiler is out of heap space

自作多情 提交于 2019-12-23 07:26:15
问题 I received this error when I added more music my resources.qrc. The mp3 files are not even that big, you have got to kidding me that this is all the MSVC compiler can handle. Is there anyway around this? Is it impossible to increase the heap space for a compiler? I guess I can store the music and search for it locally, but then how do I deploy these resources to the phone? 回答1: There's a workaround for this in Qt 5.4.0 : Use CONFIG += resources_big in your .pro file. See also the 'rcc'

How do I show a message box with Qt Quick Controls?

ε祈祈猫儿з 提交于 2019-12-23 06:59:08
问题 What is the equivalent of QMessageBox::information() when one wishes to write a QML application using Qt Quick Controls? 回答1: In Qt 5.2 there is MessageDialog: http://doc.qt.io/qt-5/qml-qtquick-dialogs-messagedialog.html import QtQuick 2.2 import QtQuick.Dialogs 1.1 MessageDialog { id: messageDialog title: "May I have your attention please" text: "It's so cool that you are using Qt Quick." onAccepted: { console.log("And of course you could only agree.") Qt.quit() } Component.onCompleted:

how can i change the text of the button without clicked in the listview delegate?

烂漫一生 提交于 2019-12-23 06:09:24
问题 I write a listview to show some information, when i clicked the button in the pDelegate , the text on the button will change to "Added", now i want to save the model's data, when i restart the program, such "Added" items will autoshow "Added",but i can't realize this. when i mark a variable to the button text,all the button text will show "Added",i just want the specific item that matched the saved data to show "Added", Please help me, thanks!!! ListModel{ id:pModel } ListView{ id:pView

How to flip an image in Qt?

女生的网名这么多〃 提交于 2019-12-23 04:53:31
问题 I found that video on Youtube. It shows how to flip something called QML Flipable. I'm completely unfamiliar with QML so I have the following questions: 1) Is it possible to flip an ordinary QLabel like this? If yes how do I do that? 2) If it's not possible then how do I add that Flipable entity to my QMainWindow? Thanks, everyone 回答1: You could use the QGraphicsPixmap with your image , set the rotation center with setTransformOriginPoint and animate the transformation matrix with