qml

How to implement rich text logic on QML TextEdit with QSyntaxHighlighter class in Qt?

南楼画角 提交于 2020-02-02 11:58:07
问题 I have a TextEdit in my QML file and I have a QSyntaxHighlighter C++ class. I want to specify the highlighting logic in the C++ class and apply it to the TextEdit, but I am not sure how to make the connection between the QML object and the C++ class. Can you also please provide some sample code? I couldn't find how to implement it with the Qt documentation. 回答1: You can use TextEdit::textDocument, which holds an instance of QQuickTextDocument, to gain access to the underlying QTextDocument

Get $HOME and/or username in QML

佐手、 提交于 2020-02-02 06:06:51
问题 I need to know how to get the user name and/or home directory of the users. I've googled around for a while but can only find the variables for C++ or BASH. How do I get the user name or home directory? I'm writing in QML. 回答1: You would have to get the Username in C++ and then exchange that data from C++ to qml. Read here how to exchange data between qml and C++. 回答2: This is how I implemented it: QmlEnvironmentVariable.h #ifndef QMLENVIRONMENTVARIABLE_H #define QMLENVIRONMENTVARIABLE_H

Get $HOME and/or username in QML

人走茶凉 提交于 2020-02-02 06:06:45
问题 I need to know how to get the user name and/or home directory of the users. I've googled around for a while but can only find the variables for C++ or BASH. How do I get the user name or home directory? I'm writing in QML. 回答1: You would have to get the Username in C++ and then exchange that data from C++ to qml. Read here how to exchange data between qml and C++. 回答2: This is how I implemented it: QmlEnvironmentVariable.h #ifndef QMLENVIRONMENTVARIABLE_H #define QMLENVIRONMENTVARIABLE_H

Get $HOME and/or username in QML

╄→гoц情女王★ 提交于 2020-02-02 06:06:13
问题 I need to know how to get the user name and/or home directory of the users. I've googled around for a while but can only find the variables for C++ or BASH. How do I get the user name or home directory? I'm writing in QML. 回答1: You would have to get the Username in C++ and then exchange that data from C++ to qml. Read here how to exchange data between qml and C++. 回答2: This is how I implemented it: QmlEnvironmentVariable.h #ifndef QMLENVIRONMENTVARIABLE_H #define QMLENVIRONMENTVARIABLE_H

Qt5 QML, when to use a ColumnLayout vs Column?

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-01 00:34:07
问题 For example, this works: import QtQuick 2.5 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.4 import QtQuick.Layouts 1.2 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") function thingWidth() { return width*80/100 } Column { spacing: 10; anchors.horizontalCenter: parent.horizontalCenter Thing { color: "red"; width: thingWidth(); } Thing { color: "yellow"; width: thingWidth(); } Thing { color: "green"; width: thingWidth(); } } } But change Column

Qml中实现多视图,多图像源(QImage / QPixmap)

笑着哭i 提交于 2020-01-31 11:24:40
【写在前面】 在 Qml 中,实现多视图很容易,无非是多个 Image 而已。 但是,如果需要动态刷新,则变得困难。 再或者,来自多个不同的图像源,将更加复杂。 实际上,这在 Qt ( Widgets ) 中实现却很容易,究其原因,是 Qml 中缺少对 QImage ( 或者说 原始图像 ) 的支持 。 即便如此,Qt 仍提供了一种解决方法。 本篇主要内容: 1、 QML 中支持 QImage / QPixmap 。 2、 QML 中实现多视图。 3、 QML 中实现多图像源视图。 【正文开始】 首先,展示一下效果图。 多视图的: 多图像源的: 想要在 QML 中实现上面的效果,必须学会在 QML 中使用 QImage / QPixmap 。 其中,核心的 Class 为 QQuickImageProvider 。 QQuickImageProvider is used to provide advanced image loading features in QML applications. It allows images in QML to be: Loaded using QPixmaps rather than actual image files. Loaded asynchronously in a separate thread. To specify that

Using a qml type as a QWindow in C++ code

谁说我不能喝 提交于 2020-01-30 08:51:07
问题 I've created a MainWindow : public QMainWindow and a qtquick ui file (for a toolbox) in qtcreator. I want the toolbox to appear as a floating subwindow in mainwindow. I'm trying to use QMdiArea for that. A tutorial I've seen says that I need to add a window to the QMdiArea like this: mdi->addSubWindow(win); where win is a QWidget . How do I use the toolbox created with qml in my C++ code? 回答1: You can use QQuickWidget but remember that the root of the QML must be an Item or a class that

Using a qml type as a QWindow in C++ code

邮差的信 提交于 2020-01-30 08:50:46
问题 I've created a MainWindow : public QMainWindow and a qtquick ui file (for a toolbox) in qtcreator. I want the toolbox to appear as a floating subwindow in mainwindow. I'm trying to use QMdiArea for that. A tutorial I've seen says that I need to add a window to the QMdiArea like this: mdi->addSubWindow(win); where win is a QWidget . How do I use the toolbox created with qml in my C++ code? 回答1: You can use QQuickWidget but remember that the root of the QML must be an Item or a class that

How to use roboto thin font in qml

霸气de小男生 提交于 2020-01-30 08:16:51
问题 I am trying to use robot thin font in QML in Linux.I have install bold,thin and light fonts on ubuntu. Other programs like openoffice shows me only roboto. How do i get to use roboto thin or light in qml? 回答1: You can bundle the font files with your application and then use FontLoader component to load the version you want and use these in QML. This component also exist for QtQuick 1.0 as it was introduced in Qt 4.7 FontLoader 回答2: FontLoader will solve the issue for Light Roboto but not for

How can we declare enumerations in QML, without any JavaScript?

拟墨画扇 提交于 2020-01-29 02:53:12
问题 Does QML allow us to define enums? If so, how we can declare enumerations in QML? I want to declare an enum in QML like the following C++ enum. If possible, I want to do this without any JavaScript. enum Color { RED, GREEN, BLUE }; Color r = RED; switch(r) { case RED : std::cout << "red\n"; break; case GREEN: std::cout << "green\n"; break; case BLUE : std::cout << "blue\n"; break; } What should I do? 回答1: You can use a pure Qml singleton, so you don't need any C++ or javascript. colors