qt-quick

Change Font Size of Button in Qt QML

為{幸葍}努か 提交于 2019-12-03 16:58:41
问题 How can the font size of the text in a Button control be set in QML? The designer has not option, and 'font' is not a valid property of Button. Button { id: cmdQuit text: qsTr("Quit") width: 64 height: 32 } 回答1: You set the Button's style property: import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 Rectangle { id: container width: 800 height: 800 Button { id: cmdQuit text: qsTr("Quit") width: 64 height: 32 style: ButtonStyle { label: Text { renderType: Text

How to change the geometry of main window programmatically at run time w.r.t QML?

浪尽此生 提交于 2019-12-03 15:43:35
I have Qt Creator 2.6.1. I created simple Qt Qucik 2.0 project from project templates and changed main.qml file on this: import QtQuick 2.0 Rectangle { width: 360 height: 360 color: "red" MouseArea { anchors.fill: parent onClicked: parent.height = 180 } } If i will click on rectangle it should be reduced in half. And it is occured, but window is not reduced. What is a best solution, if i want that main window must repeat geometry of main qml rectangle? UPDATE. One solution was found. See Amit Tomar answer. But is exist more easier solution, for example, using QtQuick 5.0: Qt Quick Window QML

How to create and use C++ objects in QML Javascript

久未见 提交于 2019-12-03 12:17:27
My app uses both c++ and QML. I've defined several objects in C++ part to access SQL etc. It looks like: class MyObject : public QObject { Q_OBJECT public: MyObject(QObject *parent = 0); Q_INVOKABLE void someFunction(const QString &query); }; qmlRegisterType<MyObject>("xxx.xxx", 1, 0, "MyObject"); Ideally, I need to use these objects only in Javascript not in QML. I tried a lot of examples and read all the documentation but still can't solve my problem. So my questions: How can I instance in Javascript an object defined in C++? I tried var obj = Qt.createComponent("MyObject"); but it seems not

QtQuick, Dynamic Images and C++

别说谁变了你拦得住时间么 提交于 2019-12-03 08:00:43
I'm new to Qt, and from what I've read on qt-project.org and other places; QtQuick seems like an attractive option because of its ability to work on both pointer and touch based devices. My problem is getting it to work well with c++. I decided to write a variant of Conway's Game of Life as a next step after "Hello World". I am thoroughly mystified as to how to get the "board" -- a [height][width][bytes-per-pixel] array of char -- integrated into the scene graph. Basically, the process is that the "LifeBoard" iterates through its rules and updates the char*/image. I've got this simple QML: ::

Does QML support access specifiers like Private for properties?

余生颓废 提交于 2019-12-03 07:01:26
问题 I just want to know do we have any concept access specifiers like private property in QML as we have in C++. If not if would like to know in case i have about 10 properties in my QML component but i have to limit the access to only 2 properties. how can we achieve this scenario. 回答1: There is no such builtin feature in QML itself, but here is Qt Quick Components approach: Item { property int sum: internal.a + internal.b QtObject { id: internal property int a: 1 property int b: 2 } }

Change Font Size of Button in Qt QML

我们两清 提交于 2019-12-03 06:50:33
How can the font size of the text in a Button control be set in QML? The designer has not option, and 'font' is not a valid property of Button. Button { id: cmdQuit text: qsTr("Quit") width: 64 height: 32 } You set the Button's style property: import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 Rectangle { id: container width: 800 height: 800 Button { id: cmdQuit text: qsTr("Quit") width: 64 height: 32 style: ButtonStyle { label: Text { renderType: Text.NativeRendering verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter font.family:

How to define a “template” with child placeholders in QML?

邮差的信 提交于 2019-12-03 04:39:06
问题 I really like QML. I like how I can define components (comparable to classes) and their properties, and instantiate them from somewhere else (comparable to objects). I can define, let's say, a button, having some look and feel, and a label text on it. This could be done, for example, using this component definition ( Button.qml ): Item { id: button property string label anchors.fill: parent Rectangle { anchors.fill: parent radius: 10 color: "gray" Text { anchors.centerIn: parent font

Applying MVVM pattern in a QtQuick

╄→гoц情女王★ 提交于 2019-12-03 04:06:48
How can i apply MVVM pattern in QtQuick applications? Can anybody give me any sample (simple) code? Thanks flex With a C++ ViewModel I know someone has done the same thing with a QML ViewModel and bi-directional binding for the text element for example. Bi-directional binding is done through the binding of the text property to the viewmodel property. Then, add a Binding node to bind the viewmodel property to the text property of the textinput. 来源: https://stackoverflow.com/questions/8533859/applying-mvvm-pattern-in-a-qtquick

How to print a QQuickView's contents to PDF?

依然范特西╮ 提交于 2019-12-02 20:53:57
I'm upgrading some Qt (C++ & QML) code from Qt4.8 to Qt5.1. The Qt4.8 code is a trivial C++ "QML viewer" app subclassing a QDeclarativeView , and a bunch of QML. It's been easy enough to change this to use Qt5/QtQuick2's QQuickView except for one thing: The Qt4.8 app has a method for printing to PDF: void MyQMLViewer::printToPDF(const QString& filename) const { QPrinter printer(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPageSize(QPrinter::A3); printer.setOutputFileName(filename); printer.setOrientation(QPrinter::Landscape); QPainter painter(&printer);

How to define a “template” with child placeholders in QML?

﹥>﹥吖頭↗ 提交于 2019-12-02 17:08:53
I really like QML. I like how I can define components (comparable to classes) and their properties, and instantiate them from somewhere else (comparable to objects). I can define, let's say, a button, having some look and feel, and a label text on it. This could be done, for example, using this component definition ( Button.qml ): Item { id: button property string label anchors.fill: parent Rectangle { anchors.fill: parent radius: 10 color: "gray" Text { anchors.centerIn: parent font.pixelSize: 20 text: button.label color: "white" } } } and instanciated in this main file ( main.qml ):