【Qt】QWidegt的enable属性

enabled:描述了一个控件是否处于“可用”状态(相对的概念“禁用”)。

API 说明

isEnabled()

获取到控件的可⽤状态

setEnabled

设置控件是否可使⽤. true 表⽰可⽤, false 表⽰禁⽤

  • 所谓“禁用”指的是该控件不能接收任何用户的输入事件,并且外观上往往是灰色的。
  • 如果一个Widget被禁用,则该widget的子元素也被禁用。

例子:创建出一个禁用的按钮 

#include "widget.h"
#include "ui_widget.h"

#include<QPushButton>
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPushButton* button = new QPushButton("按钮",this);
    //将按钮处于禁用状态
    button->setEnabled(false);
    //将按钮信号与槽建立联系
    connect(button, &QPushButton::clicked, this, &Widget::handleButton);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::han
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值