qt窗口及组件的使用

 mywidget.h

#ifndef MYWIDGET_H
#define MYWIDGET_H

#include <QWidget>
#include <QIcon>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>

class MyWidget : public QWidget
{
    Q_OBJECT

public:
    MyWidget(QWidget *parent = nullptr);
    ~MyWidget();
};
#endif // MYWIDGET_H

 mywidget.cpp

#include "mywidget.h"

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    //窗口设置
    this->resize(500,500);//设置窗口大小为500*500
    this->setStyleSheet("background-color:rgb(0,255,255)");//设置窗口背景颜色
    this->setWindowIcon(QIcon("C:\\Users\\ghy\\Desktop\\pictrue\\pictrue\\heartstone.jpg"));//设置窗口图标
    this->setWindowTitle("heartstone");//设置窗口标题

    QLabel *lab3 = new QLabel(this);//创建标签并且指定父对象
    lab3->setPixmap(QPixmap("C:\\Users\\ghy\\Desktop\\pictrue\\pictrue\\123.jpg"));//设置图片
    lab3->setScaledContents(true);//让图片自动适应lab


    //按钮类设置
    QPushButton *btn1 = new QPushButton("Login in",this);//创建按钮并设置按钮文本,并且指定父对象
    btn1->resize(100,40);//设置btn1按钮大小
    btn1->move(200,400);//移动btn1位置
    btn1->setStyleSheet("background: qradialgradient(cx:0.5,cy:0.5,radius:1,fx:0.5,fy:0.5,stop:0#66CCFF,stop:1#3366CC);"
                        "hover { background-color: #3e8e41;pressed { background-color: #3366CC;border-radius: 5px");//设置btn1颜色,悬停颜色及按下颜色

    //标签类设置
    QLabel *lab1 = new QLabel("Username",this);//创建标签并设置标签文本,并且指定父对象
    lab1->resize(80,40);//设置lab1标签大小
    lab1->move(75,100);//移动lab1位置
    lab1->setStyleSheet("background-color:green;border-radius: 5px");//设置lab1标签颜色

    QLabel *lab2 = new QLabel("Password",this);//创建标签并设置标签文本,并且指定父对象
    lab2->resize(80,40);//设置lab2标签大小
    lab2->move(75,200);//移动lab2位置
    lab2->setStyleSheet("background-color:green;border-radius: 5px");//设置lab2标签颜色



    //行编辑器类设置
    QLineEdit *edit1 = new QLineEdit(this);//创建行编辑器,并指定父对象
    edit1->resize(200,40);//设置行编辑器大小
    edit1->move(200,100);//移动edit1位置
    edit1->setPlaceholderText("please enter username");//设置占位

    QLineEdit *edit2 = new QLineEdit(this);//创建行编辑器,并指定父对象
    edit2->resize(200,40);//设置行编辑器大小
    edit2->move(200,200);//移动edit1位置
    edit2->setPlaceholderText("please enter password");//设置占位
    edit2->setEchoMode(QLineEdit::Password);//设置显示模式为密码显示
}

MyWidget::~MyWidget()
{
}

结果展示

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值