QT常用控件

目录

enabled

geometry

windowTitle

windowIcon

toolTip


enabled

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

isEnabled()  获取到控件的可⽤状态.
setEnabled() 设置控件是否可使⽤. true 表⽰可⽤, false 表⽰禁⽤
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPushButton *newbutton=new QPushButton(this);
    bool flag=newbutton->isEnabled();
    newbutton->setText(QString("这是个被禁⽤的按钮"));
    if(flag) newbutton->setEnabled(false);
}

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

geometry

位置和尺⼨. 其实是四个属性的统称:
x 横坐标
y 纵坐标
width 宽度
height ⾼度

Qt坐标系 

geometry()
获取到控件的位置和尺⼨.
返回结果是⼀个 QRect, 包含了 x, y,  控件大小(width, height)     其 中 x, y 是左上⻆的坐标.
setGeometry(QRect)
setGeometry(int x, int y, int width, int height)
设置控件的位置和尺⼨. 可以直接设置⼀个 QRect, 也可以分四个属性单独设置.

 QRect rect = ui->pushButton_target->geometry();
ui->pushButton_target->
setGeometry(rect.x(), rect.y() + 5, rect.width(),rect.height());
//x+往右
//x-往左
//y+往下
//y-往上
//看上面坐标系

windowTitle

windowTitle()
获取到控件的窗⼝标题.
setWindowTitle(const QString& title)
设置控件的窗⼝标题.

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

 // 设置窗⼝标题
 this->setWindowTitle("这是标题");
 }

windowIcon

windowIcon()
获取到控件的窗⼝图标. 返回 QIcon 对象.
setWindowIcon(const QIcon& icon)
设置控件的窗⼝图标

#include <QIcon>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
// 创建图标对象
QIcon icon("想添加的图片路径");
// 设置图标
this->setWindowIcon(icon);
}

toolTip

setToolTip("提示说明")
设置 toolTip. ⿏标悬停在该 widget 上时会有提⽰说明.
setToolTipDuring(多少ms)
设置 toolTip 提⽰的时间. 单位 ms. 时间到后 toolTip ⾃动消失.
Widget::Widget(QWidget *parent)
 : QWidget(parent)
 , ui(new Ui::Widget)
 {
     ui->setupUi(this);

     ui->pushButton_yes->setToolTip("这个是 yes 按钮");
     ui->pushButton_yes->setToolTipDuration(3000);

     ui->pushButton_no->setToolTip("这个是 no 按钮");
     ui->pushButton_no->setToolTipDuration(10000);
 }

博主以后想到什么就更新 

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值