小编pra*_*ra7的帖子

QML 中的动画进度条

我需要使用 QML Controls 2 创建如下进度条: 在此处输入图片说明

    ProgressBar{
    id:progressBar
    width : parent.width * 0.80
    height:parent.height * 0.05
    anchors.bottom:parent.bottom
    anchors.bottomMargin: (parent.height * 0.03)
    anchors.left:parent.left
    anchors.leftMargin: (parent.width * 0.05)
    value : 0.5

    background: Rectangle {
        color: "#e6e6e6"
        radius: 3
    }

    contentItem: Item {        
        Rectangle {
            width: progressBar.visualPosition * parent.width
            height: parent.height
            radius: 2
            color: "#17a81a"

            gradient: Gradient {
                GradientStop {
                    position: 0.0
                    SequentialAnimation on color {
                        loops: Animation.Infinite
                        ColorAnimation { from: "#14148c"; to: "#0E1533"; duration: 5000 }
                        ColorAnimation { from: "#0E1533"; to: "#14148c"; duration: …
Run Code Online (Sandbox Code Playgroud)

qt qml progress-bar qtquick2 qtquickcontrols2

5
推荐指数
1
解决办法
5343
查看次数

QML SwipeView 覆盖整个窗口

如果我使用滑动视图,我会遇到一些问题,并且我编写了以下代码:

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Swipe View")

    MainForm {
        anchors.fill:parent

        Rectangle{
            id:rightRect
            anchors.right:parent.right
            width: parent.width*0.50
            height:parent.height
            color:"yellow"
        }

        Rectangle{
            id:leftRect
            width:parent.width*0.50
            height:parent.height
            color:"lightgreen"
            border.color:"red"
            anchors.right:rightRect.left
            SwipeView{
                id:swipeView
                anchors.fill : leftRect
                //Layout.fillWidth: true
                currentIndex: 0
                interactive: false
                Page{
                    id:page1

                    Rectangle{
                        width:parent.width
                        height:parent.height
                        color:"lightgreen"
                        Button{
                            text:"move to 2"
                            onClicked: swipeView.currentIndex = 1
                        }
                    }
                }

                Page{
                    id:page2
                    Rectangle{
                        width:parent.width
                        height:parent.height
                        color:"lightblue"
                        Button{
                            text:"move to 1"
                            onClicked: swipeView.currentIndex = …
Run Code Online (Sandbox Code Playgroud)

qt qml qtquick2 qtquickcontrols qtquickcontrols2

4
推荐指数
1
解决办法
1610
查看次数

在 QML 中动态添加 TabButton 到 TabBar

我试图在按下按钮时动态地将 tabButton 添加到TabBar但我花了很多时间搜索但我不知道如何添加,下面是我正在处理的代码:

我的选项卡按钮.qml

import QtQuick 2.4
import QtQuick.Controls 2.2

Item
{
    property int BtnWidth:0
    property int BtnHeight:0
    property string BtnText: ""
    property bool isChecked : false

    TabButton
    {
        id:tabBtn
        text:BtnText
        width:BtnWidth
        height:BtnHeight

    }
}
Run Code Online (Sandbox Code Playgroud)

MainForm.qml

import QtQuick 2.4
import QtQuick.Controls 2.2

Rectangle
{
    Button
    {
        id:button
        width:100
        height:100
        anchors.top:parent.top
        text:qStr("Add")
        onClicked{
            //How to add logic here to add tab in below tabBar.
        }
    }
    TabBar
    {
        id:tabBar
        anchors.top:button.bottom
        width:500
        height:500
    }
}
Run Code Online (Sandbox Code Playgroud)

qt qml qtquick2 qtquickcontrols qtquickcontrols2

3
推荐指数
1
解决办法
4433
查看次数

在QML中访问cpp结构的最佳方法

我需要在cpp和QML之间传递结构。如果我使用属性,我应该创建一个单独的集合并获取函数,我的结构至少包含5个成员,所以我觉得对所有这些成员使用集合并获取并不好。以下是我要执行的操作的示例:

MyClass.h

#include <QObject>
#include <QDebug>
using namespace std;

struct MyStruct {
Q_GADGET
int m_val;
QString m_name1;
QString m_name2;
QString m_name3;
QString m_name4;
Q_PROPERTY(int val MEMBER m_val)
Q_PROPERTY(QString name1 MEMBER m_name1)
Q_PROPERTY(QString name2 MEMBER m_name2)
Q_PROPERTY(QString name3 MEMBER m_name3)
Q_PROPERTY(QString name4 MEMBER m_name4)
};

class MyClass:public QObject
    {
        Q_OBJECT
    Q_PROPERTY(MyStruct mystr READ getMyStruct
                WRITE setMyStruct NOTIFY myStructChanged)

public:
    explicit MyClass(QObject *parent = nullptr);
    MyStruct strObj;

     // Edit: changed get function
     MyStruct getMyStruct() const
     {
         return strObj;
     }

// …
Run Code Online (Sandbox Code Playgroud)

qt qvariant qml qt-quick qtquick2

3
推荐指数
2
解决办法
4794
查看次数

如何使用QML StackView?

我是QMl的初学者,在QT C++中使用StackWidget做了更多.在QML中,我很困惑使用stackView并编写了以下代码:

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Stack view")

    MainForm {
        StackView {
            id: stackView
            x: 0
            y: 0
            width: 360
            height: 360

            initialItem: page1

            Rectangle {
                id: page1

                //anchors.fill: parent
                color: "lightgreen"
                Button {
                    id: buttonPage1
                    text: "back to 2"
                    anchors.centerIn: parent
                    onClicked: {
                        stackView.pop()  //**Is THIS CORRECT**
                        stackView.push(page2) //**Is THIS CORRECT**

                    }
                }
                TextEdit {
                    id: te1
                    width: 105
                    height: 40
                    text: "enter"
                }
            }
            Rectangle {
                id: page2

                //anchors.fill: …
Run Code Online (Sandbox Code Playgroud)

qt qml qt-quick qtquick2 qtquickcontrols

2
推荐指数
1
解决办法
5500
查看次数

在 QML 中将 TextArea 光标移动到 MouseArea 单击上

有一个 TextArea,我已将activeFocusOnPress属性设置为false阻止虚拟键盘弹出,但是当用户单击 TextArea 时,光标位置应该移动。为了实现这一目标,我认为 mousearea 将是一个不错的选择。以下是代码:

TextArea{
    id:textArea
    text:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"    
    width:100
    height: 200
    color: "white"
    cursorVisible: true
    activeFocusOnPress: false //To Block virtual Keyboard popup

    background: Rectangle{
        color:"transparent"
        border.color : "white"
        border.width:2
        MouseArea{
            id:mousearea
            anchors.fill:parent
            onClicked: {

                //*** How to set cursor position??                    
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

qt qml qtquick2 qtquickcontrols2

2
推荐指数
1
解决办法
1643
查看次数

QML 2 中的 GroupBox 样式

我想在 QML 2 中设置 GroupBox 的样式,如下所示:

在此输入图像描述

我没有找到如何在 QML 2 中执行此操作。在下一页“自定义 Qt Quick 控件”中,没有有关样式标题的信息。

qt qml qtquick2 qtquickcontrols2

2
推荐指数
1
解决办法
5850
查看次数

QML中日期和时间的正则表达式(DD/MM/YYYY hh:mm:ss)

在 QML2 中,我没有找到任何Calender控件,我已经实现了一个将日期和时间作为输入的控件,并且我正在使用正则表达式进行验证,它匹配包括闰年和其他验证在内的日期。

主要问题是空格/退格也应视为有效,例如:

\s\s/\s\s/\s\s \s\s:\s\s:\s\s

以下是代码:

TextField{
    id:textEditDate

    width:parent.width * 0.50
    height:parent.height
    text : "01/01/2017 00:00:00"

    inputMask: "99/99/9999 99:99:99"

    validator: RegExpValidator { regExp: /^(((([0\s][1-9\s]|[1\s][0-9\s]|[2\s][0-8\s])[\/]([0\s][1-9\s]|[1\s][012\s]))|((29|30|31)[\/]([0\s][13578\s]|[1\s][02\s]))|((29|30)[\/]([0\s][4,6,9]|11)))[\/]([19\s[2-9\s][0-9\s])\d\d|(^29[\/]02[\/]([19\s]|[2-9\s][0-9\s])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)))\s([0-1\s]?[0-9\s]|2[0-3\s]):([0-5\s][0-9\s]):([0-5\s][0-9\s])$/}

    horizontalAlignment: Text.AlignHCenter
    inputMethodHints: Qt.ImhDigitsOnly
}
Run Code Online (Sandbox Code Playgroud)

现在,除年份外,一切正常,我无法匹配年份的退格/空格,用户也无法清除年份。

你能建议如何实现这一目标吗?或者有没有其他方法可以做到这一点。

regex qt datetime qml qtquick2

1
推荐指数
1
解决办法
1808
查看次数

在 QML 2.0 中设置忙碌指示器的样式

我正在使用忙碌指示器来显示中间进度,并且我想更改圆圈的颜色。我提到了自定义忙碌指示器链接,但这正在更改默认动画和其他内容。此外,它很难理解,因为没有对此进行解释。

我只想更改颜色,动画应该与默认值相同。请建议。

qt busyindicator qml qtquick2

1
推荐指数
1
解决办法
2776
查看次数