目录
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);
}
博主以后想到什么就更新