QML control--DelayButton

Article directory

  • 1. Basic information of controls
  • 2. Use of controls
  • 3. Attributes
  • 4. Signal

1. Basic information of controls

Import Statement:import QtQuick.Controls 2.14

Since:Qt 5.9

Inherits:AbstractButton

2. Use of controls

DelayButton is a delay button that requires a long press to trigger. This delay can prevent accidental presses;

The current progress is expressed as a decimal value between 0.0 and 1.0;

The time required to activate the trigger is in milliseconds and can be set using the delay attribute;

Progress is indicated by a progress indicator on the button;

import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.3

ApplicationWindow{
    visible: true;
    width: 1280;
    height: 720;

    property int count: 0

    Label{
        id: lbl;
        text: "未点击";
        font.bold: true;
        font.pixelSize: 28;
        anchors.centerIn: parent;
    }

    DelayButton{
        id: delayBtn;
        delay: 1000
        text: "PressAndHold";

        onActivated: {
            lbl.text = "已点击";
            timer.start();
        }
    }

    Timer {
        id: timer;
        interval: 2000;  //设置定时器定时时间2000ms(默认1000ms)
        repeat: false   //是否重复定时,默认为false
        running: false  //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
        triggeredOnStart: false     //是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
        onTriggered: {
            lbl.text = "未点击";  //定时触发槽,定时完成一次就进入一次
        }
        //restart ,start,stop,定时器的调用方式,顾名思义
    }

}

Note: Long press the button to activate, then click again to reset, but this process does not provide any signal for monitoring;

3. Attributes

delay:int button activation delay time (in milliseconds);

progress:real The current progress displayed by the progress indicator, ranging from 0.0 - 1.0;

transition:Transition The transition applied to the progress property when the button is pressed or released

4. Signal

activated(): This signal will be emitted when the progress reaches 1.0

Benefits of this article, receive free Qt development learning materials package and technical videos, including (Qt practical project video tutorial + code, C++ Language foundation, C++ design pattern, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project practice, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓ ↓↓↓See below↓↓Click at the bottom of the article to receive the fee↓↓

Guess you like

Origin blog.csdn.net/hw5230/article/details/134855956