QT笔记---UI学习

UI学习
添加图片素材的步骤:新建文件—QT—-Resources File—–(先将素材加入工程),添加现有文件
右击图片会有copy path选项

注意:
相应控件头文件要添加
使用帮助文档获取信息,有的类有继承关系,有的方法可能在父类中
关注文档相应类的public function 和 signals
关注方法的参数,返回值类型

以下是简单实现各个控件功能
/1.将按钮替换成图片,功能不变/
this->resize(320,480);
QPushButton* b1 = new QPushButton(this);
b1->move(250,10);
QPixmap icon(“:/pictures/props_paint.png”);//生成图片对象 QPixmap 和处理图片有关
b1->setIcon(icon);
b1->setFixedSize(icon.size());//将按钮大小设置为源图片大小
b1->setIconSize(icon.size());//将显示图片的大小设置为源图片的大小
b1->setFlat(true);//去除边框
connect(b1,&QPushButton::pressed,this,={
qDebug()<<”我被点击”;
});

/2.标签/
QLabel* label = new QLabel(this);
label->setText(“百度“);
connect(label,&QLabel::linkActivated,this,[=](QString str){
QDesktopServices::openUrl(QUrl(str));
});
//linkActivated连接被激活 openUrl(QUrl(str)打开网页,注意str的类型转换

/3.单行文本输入/
QLineEdit* lineEdit2 = new QLineEdit(this);
lineEdit2->move(0,20);
lineEdit2->setEchoMode(QLineEdit::NoEcho);//setEchoMode()设置显示模式

QLineEdit* lineEdit = new QLineEdit(this);
lineEdit->move(0,50);
lineEdit->setMaxLength(10);//设置最大的输入长度
lineEdit->setEchoMode(QLineEdit::Password);//输入以密码隐藏
lineEdit->setPlaceholderText("提示输入");//框里初始提示信息,用户输入则会消失
connect(lineEdit,&QLineEdit::returnPressed,this,[=](){
    qDebug()<<"密码输入完毕,回车被按下";
});

/4.多行文本输入/
textEdit = new QTextEdit(this);
textEdit->move(0,200);
connect(textEdit,&QTextEdit::textChanged,this,receiveTextChange);

/5.单选按钮,具有互斥性/
QRadioButton* radioButton = new QRadioButton(this);
radioButton->setText(“male”);
radioButton->move(0,80);

QRadioButton* radioButton2 = new QRadioButton(this);
radioButton2->setText("female");
radioButton2->move(0,100);

/*12一组,34一组*/
QRadioButton* radioButton3 = new QRadioButton(this);
radioButton3->setText("studnt");
radioButton3->move(60,80);

QRadioButton* radioButton4 = new QRadioButton(this);
radioButton4->setText("teachter");
radioButton4->move(60,100);

/6.单选按钮分组整合/
QButtonGroup* box = new QButtonGroup(this);
box->addButton(radioButton3);//将34按钮用box整合,否则在一个视图下,这四个按钮互斥
box->addButton(radioButton4);

/7.选择框/
QCheckBox* checkBox = new QCheckBox(“买”,this);
checkBox->move(130,80);

QCheckBox* checkBox2 = new QCheckBox("不买",this);
checkBox2->move(130,100);

/8.下拉选择框/
QComboBox* comboBox = new QComboBox(this);
comboBox->move(180,80);
comboBox->addItem(“鸡”);
comboBox->addItem(“鸭”);
comboBox->addItem(“鱼”);
comboBox->setCurrentIndex(2);//以下标确定从哪个item开始
comboBox->setCurrentText(“鸭”);//以内容确定从哪个item开始

/9.滑动器/
QSlider* slider = new QSlider(this);
slider->move(0,300);
slider->setMaximum(99);
slider->setMinimum(1);
connect(slider,&QSlider::valueChanged,this,={
qDebug()<value();

/10.滑动器数值显示,和滑动器互相绑定/
QSpinBox* spinBox = new QSpinBox(this);
spinBox->move(20,300);
connect(slider,&QSlider::valueChanged,spinBox,&QSpinBox::setValue);//滑动条做信号
//因为valueChanged重载了,所以用函数指针区别
void (QSpinBox::*p)(int) = QSpinBox::valueChanged;
connect(spinBox,p,slider,&QSlider::setValue);//数值显示做信号

/11.时间日期/
QDateEdit* dateEdit = new QDateEdit(QDate::currentDate(),this);//当前时间
dateEdit->move(80,300);
qDebug()<date().year();//分别获取年月日
qDebug()<date().month();
qDebug()<date().day();
qDebug()<date();//获取所有

QTimeEdit* timeEdit = new QTimeEdit(QTime::currentTime(),this);
timeEdit->move(80,320);
qDebug()<<timeEdit->time().hour();//hour()返回的是一个整型
qDebug()<<timeEdit->time();//获取所有时间

QDateTimeEdit* dateTimeEdit = new QDateTimeEdit(QDateTime::currentDateTime(),this);
dateTimeEdit->move(80,340);//宽,高
qDebug()<<dateTimeEdit->dateTime().date().year();//一层层包含
qDebug()<<dateTimeEdit->dateTime();//获取所有

/12.通过日历输入日期/
dateEdit->setCalendarPopup(true);//以日历的形式提供时间输入选择

/13.数码管/
QLCDNumber* lcdNum = new QLCDNumber(this);
lcdNum->move(80,400);
lcdNum->display(“2018”);//数码管显示内容,数码管用来显示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值