ui_myqt.h
/********************************************************************************
** Form generated from reading UI file 'myqt.ui'
**
** Created by: Qt User Interface Compiler version 5.14.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MYQT_H
#define UI_MYQT_H
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_myqtClass
{
public:
QPushButton *closeWindow;
QPushButton *minwindow;
QLabel *label;
QLabel *labe2;
QPushButton *shotPushButton;
QPushButton *styleButton;
QPushButton *PicButton;
QLineEdit *lineEdit;
QPushButton *changeButton;
QLabel *viewlabel;
QPushButton *changeButton_2;
QLineEdit *lineEdit_2;
QLineEdit *lineEdit_3;
QLineEdit *lineEdit_4;
QPushButton *pushButton;
QPushButton *pushButton_2;
QLineEdit *textEdit;
QLineEdit *ipEdit;
QLineEdit *intEdit;
QLineEdit *doubleEdit;
QLineEdit *emailEdit;
QPushButton *pushButton_3;
QLineEdit *sEdit;
QLabel *slabel;
QLabel *rlabel;
QLineEdit *passwordEdit;
void setupUi(QWidget *myqtClass)
{
if (myqtClass->objectName().isEmpty())
myqtClass->setObjectName(QString::fromUtf8("myqtClass"));
myqtClass->resize(860, 614);
closeWindow = new QPushButton(myqtClass);
closeWindow->setObjectName(QString::fromUtf8("closeWindow"));
closeWindow->setGeometry(QRect(470, 390, 93, 28));
minwindow = new QPushButton(myqtClass);
minwindow->setObjectName(QString::fromUtf8("minwindow"));
minwindow->setGeometry(QRect(470, 440, 93, 28));
label = new QLabel(myqtClass);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(550, 70, 261, 121));
label->setStyleSheet(QString::fromUtf8("background-color: rgb(85, 255, 255);\n"
"font: 16pt \"\351\273\221\344\275\223\";\n"
"color: rgb(255, 0, 127);"));
label->setAlignment(Qt::AlignCenter);
label->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse);
labe2 = new QLabel(myqtClass);
labe2->setObjectName(QString::fromUtf8("labe2"));
labe2->setGeometry(QRect(580, 180, 281, 441));
labe2->setStyleSheet(QString::fromUtf8("image: url(:/myqt/R-C.gif);\n"
""));
shotPushButton = new QPushButton(myqtClass);
shotPushButton->setObjectName(QString::fromUtf8("shotPushButton"));
shotPushButton->setGeometry(QRect(470, 500, 93, 28));
styleButton = new QPushButton(myqtClass);
styleButton->setObjectName(QString::fromUtf8("styleButton"));
styleButton->setGeometry(QRect(450, 537, 121, 71));
styleButton->setStyleSheet(QString::fromUtf8("QPushButton{\n"
"font: 14pt \"\345\276\256\350\275\257\351\233\205\351\273\221\";\n"
"color: rgb(0, 255, 0);\n"
"border-radius:10px;\n"
"}\n"
"QPushButton::!hover{\n"
"background-color:qlineargradient(spread:reflect, x1:1, y1:0.46, x2:1, y2:1, stop:0.114428 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
"}\n"
"QPushButton::hover{\n"
"background-color:qlineargradient(spread:reflect, x1:1, y1:1, x2:1, y2:1, stop:0.114428 rgba(0, 0, 0, 255), stop:1 rgba(255, 255, 255, 255));\n"
"}\n"
""));
PicButton = new QPushButton(myqtClass);
PicButton->setObjectName(QString::fromUtf8("PicButton"));
PicButton->setGeometry(QRect(280, 390, 181, 131));
PicButton->setStyleSheet(QString::fromUtf8("background-image: url(:/myqt/qt.PNG);"));
PicButton->setFlat(true);
lineEdit = new QLineEdit(myqtClass);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(20, 500, 141, 31));
lineEdit->setReadOnly(false);
lineEdit->setClearButtonEnabled(true);
changeButton = new QPushButton(myqtClass);
changeButton->setObjectName(QString::fromUtf8("changeButton"));
changeButton->setGeometry(QRect(170, 500, 101, 31));
viewlabel = new QLabel(myqtClass);
viewlabel->setObjectName(QString::fromUtf8("viewlabel"));
viewlabel->setGeometry(QRect(280, 220, 261, 111));
viewlabel->setStyleSheet(QString::fromUtf8("background-color: rgb(85, 170, 255);"));
changeButton_2 = new QPushButton(myqtClass);
changeButton_2->setObjectName(QString::fromUtf8("changeButton_2"));
changeButton_2->setGeometry(QRect(130, 580, 101, 31));
lineEdit_2 = new QLineEdit(myqtClass);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
lineEdit_2->setGeometry(QRect(20, 450, 141, 31));
lineEdit_2->setClearButtonEnabled(true);
lineEdit_3 = new QLineEdit(myqtClass);
lineEdit_3->setObjectName(QString::fromUtf8("lineEdit_3"));
lineEdit_3->setGeometry(QRect(20, 410, 141, 31));
lineEdit_3->setReadOnly(true);
lineEdit_4 = new QLineEdit(myqtClass);
lineEdit_4->setObjectName(QString::fromUtf8("lineEdit_4"));
lineEdit_4->setGeometry(QRect(20, 370, 141, 31));
lineEdit_4->setMaxLength(3);
pushButton = new QPushButton(myqtClass);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(20, 540, 93, 28));
pushButton_2 = new QPushButton(myqtClass);
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(130, 540, 93, 28));
textEdit = new QLineEdit(myqtClass);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setGeometry(QRect(180, 350, 113, 21));
ipEdit = new QLineEdit(myqtClass);
ipEdit->setObjectName(QString::fromUtf8("ipEdit"));
ipEdit->setGeometry(QRect(310, 350, 181, 21));
intEdit = new QLineEdit(myqtClass);
intEdit->setObjectName(QString::fromUtf8("intEdit"));
intEdit->setGeometry(QRect(280, 180, 113, 21));
doubleEdit = new QLineEdit(myqtClass);
doubleEdit->setObjectName(QString::fromUtf8("doubleEdit"));
doubleEdit->setGeometry(QRect(420, 180, 113, 21));
emailEdit = new QLineEdit(myqtClass);
emailEdit->setObjectName(QString::fromUtf8("emailEdit"));
emailEdit->setGeometry(QRect(260, 130, 171, 21));
pushButton_3 = new QPushButton(myqtClass);
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
pushButton_3->setGeometry(QRect(440, 130, 93, 28));
sEdit = new QLineEdit(myqtClass);
sEdit->setObjectName(QString::fromUtf8("sEdit"));
sEdit->setGeometry(QRect(280, 90, 113, 21));
slabel = new QLabel(myqtClass);
slabel->setObjectName(QString::fromUtf8("slabel"));
slabel->setGeometry(QRect(420, 70, 72, 15));
rlabel = new QLabel(myqtClass);
rlabel->setObjectName(QString::fromUtf8("rlabel"));
rlabel->setGeometry(QRect(420, 100, 72, 15));
passwordEdit = new QLineEdit(myqtClass);
passwordEdit->setObjectName(QString::fromUtf8("passwordEdit"));
passwordEdit->setGeometry(QRect(280, 20, 181, 31));
passwordEdit->setStyleSheet(QString::fromUtf8("QLineEdit{\n"
" border:3px dotted rgba(255,0,0,150);\n"
" border-radius:10px;\n"
" background-color:rgb(53,146,244);\n"
" front:14pt '\351\273\221\344\275\223';\n"
"}\n"
"QLineEdit[echoMode=\"2\"]{\n"
" lineedit-password-character:9731;\n"
"}"));
passwordEdit->setEchoMode(QLineEdit::Password);
retranslateUi(myqtClass);
QObject::connect(minwindow, SIGNAL(clicked()), myqtClass, SLOT(showMinimized()));
QObject::connect(closeWindow, SIGNAL(clicked()), myqtClass, SLOT(close()));
QObject::connect(label, SIGNAL(linkActivated(QString)), myqtClass, SLOT(Act(QString)));
QObject::connect(label, SIGNAL(linkHovered(QString)), myqtClass, SLOT(Hover(QString)));
QObject::connect(shotPushButton, SIGNAL(pressed()), myqtClass, SLOT(Pressed()));
QObject::connect(shotPushButton, SIGNAL(released()), myqtClass, SLOT(Released()));
QObject::connect(PicButton, SIGNAL(pressed()), myqtClass, SLOT(Pressed()));
QObject::connect(styleButton, SIGNAL(pressed()), myqtClass, SLOT(Pressed()));
QObject::connect(changeButton, SIGNAL(clicked()), myqtClass, SLOT(Test()));
QObject::connect(changeButton_2, SIGNAL(clicked()), myqtClass, SLOT(View()));
QObject::connect(pushButton, SIGNAL(clicked()), lineEdit, SLOT(undo()));
QObject::connect(pushButton_2, SIGNAL(clicked()), lineEdit, SLOT(redo()));
QObject::connect(ipEdit, SIGNAL(returnPressed()), myqtClass, SLOT(View()));
QObject::connect(textEdit, SIGNAL(returnPressed()), myqtClass, SLOT(View()));
QObject::connect(pushButton_3, SIGNAL(clicked()), myqtClass, SLOT(Save()));
QObject::connect(sEdit, SIGNAL(editingFinished()), myqtClass, SLOT(Edit()));
QObject::connect(sEdit, SIGNAL(returnPressed()), myqtClass, SLOT(Return()));
QObject::connect(sEdit, SIGNAL(textEdited(QString)), myqtClass, SLOT(Edited()));
QObject::connect(sEdit, SIGNAL(textChanged(QString)), myqtClass, SLOT(Change(QString)));
QMetaObject::connectSlotsByName(myqtClass);
} // setupUi
void retranslateUi(QWidget *myqtClass)
{
myqtClass->setWindowTitle(QCoreApplication::translate("myqtClass", "myqt", nullptr));
closeWindow->setText(QCoreApplication::translate("myqtClass", "\345\205\263\351\227\255\347\252\227\345\217\243", nullptr));
minwindow->setText(QCoreApplication::translate("myqtClass", "\346\234\200\345\260\217\345\214\226\347\252\227\345\217\243", nullptr));
label->setText(QCoreApplication::translate("myqtClass", "<html><head/><body><p>TextLabel<br/>nihao<a href=\"www.baidu.com\"><span style=\" text-decoration: underline; color:#0000ff;\">\351\223\276\346\216\245</span></a></p></body></html>", nullptr));
labe2->setText(QString());
shotPushButton->setText(QCoreApplication::translate("myqtClass", "&D\346\265\213\350\257\225\346\214\211\351\222\256", nullptr));
styleButton->setText(QCoreApplication::translate("myqtClass", "\346\240\267\345\274\217\346\214\211\351\222\256", nullptr));
PicButton->setText(QString());
changeButton->setText(QCoreApplication::translate("myqtClass", "\346\224\271\345\217\230lineedit", nullptr));
viewlabel->setText(QString());
changeButton_2->setText(QCoreApplication::translate("myqtClass", "\346\230\276\347\244\272\345\210\260view", nullptr));
lineEdit_2->setText(QCoreApplication::translate("myqtClass", "\344\270\200\346\254\241\346\200\247\345\210\240\351\231\244", nullptr));
lineEdit_3->setText(QCoreApplication::translate("myqtClass", "\345\217\252\350\257\273 \344\270\215\345\217\257\347\274\226\350\276\221", nullptr));
lineEdit_4->setPlaceholderText(QCoreApplication::translate("myqtClass", "\346\234\200\345\244\232\344\270\211\344\275\215", nullptr));
pushButton->setText(QCoreApplication::translate("myqtClass", "\346\222\244\351\224\200", nullptr));
pushButton_2->setText(QCoreApplication::translate("myqtClass", "\351\207\215\345\201\232", nullptr));
textEdit->setPlaceholderText(QCoreApplication::translate("myqtClass", "AAAAA", nullptr));
ipEdit->setPlaceholderText(QCoreApplication::translate("myqtClass", "ip", nullptr));
intEdit->setPlaceholderText(QCoreApplication::translate("myqtClass", "\345\217\252\350\203\275\350\276\223\345\205\245\346\225\264\346\225\260", nullptr));
doubleEdit->setPlaceholderText(QCoreApplication::translate("myqtClass", "\345\217\252\350\203\275\350\276\223\345\205\245\346\265\256\347\202\271\346\225\260", nullptr));
emailEdit->setPlaceholderText(QCoreApplication::translate("myqtClass", "\350\276\223\345\205\245\351\202\256\347\256\261", nullptr));
pushButton_3->setText(QCoreApplication::translate("myqtClass", "\344\277\235\345\255\230\346\240\241\351\252\214", nullptr));
slabel->setText(QCoreApplication::translate("myqtClass", "slabel", nullptr));
rlabel->setText(QCoreApplication::translate("myqtClass", "rlabel", nullptr));
passwordEdit->setText(QCoreApplication::translate("myqtClass", "dsfsd", nullptr));
} // retranslateUi
};
namespace Ui {
class myqtClass: public Ui_myqtClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MYQT_H
myqt.h
#pragma once
#include <QtWidgets/QWidget>
#include "ui_myqt.h"
#include <QDebug>
class myqt : public QWidget
{
Q_OBJECT
public:
myqt(QWidget *parent = Q_NULLPTR);
public slots:
void Act(QString url) //点击超链接触发的槽函数
{
qDebug() << "click" << url << endl;
qDebug() << ui.label->selectedText();
}
void Hover(QString url) //鼠标移动到超链接执行的槽函数
{
qDebug() << "Hover" << url << endl;
qDebug() << ui.label->selectedText(); //显示选中的文本
}
void Pressed()
{
qDebug() << "pressed";
}
void Released()
{
qDebug() << "released";
}
void Test();
void View();
void Save();
void Edit();
void Return();
void Edited(QString txt);
void Change(QString txt);
private:
Ui::myqtClass ui;
};
myqt.cpp
#include "myqt.h"
#include <QMovie>
#include <QIntValidator>
void myqt::Test()
{
ui.lineEdit->setText(QString::fromLocal8Bit("你好"));
}
void myqt::View()
{
QString txt = ui.ipEdit->text();
txt += " ";
txt += ui.textEdit->text();
txt += " ";
txt += ui.lineEdit->text();
ui.viewlabel->setText(txt);
}
void myqt::Save()
{
//格式不正确校验
const QValidator* v = ui.emailEdit->validator();
int pos = 0;
QString txt = ui.emailEdit->text();
if (v->validate(txt, pos) != QValidator::Acceptable)
{
ui.label->setText(QString::fromLocal8Bit("邮箱格式不正确!"));
}
else
ui.label->setText(QString::fromLocal8Bit("邮箱格式正确!"));
}
void myqt::Edit()
{
ui.slabel->setText(ui.sEdit->text());
}
void myqt::Return()
{
ui.rlabel->setText(ui.sEdit->text());
}
void myqt::Change(QString txt)
{
ui.slabel->setText(txt);
}
void myqt::Edited(QString txt)
{
ui.slabel->setText(txt);
}
myqt::myqt(QWidget *parent) : QWidget(parent)
{
ui.setupUi(this);
QString str = QStringLiteral("测试的中文");
//ui.label->setText(str);
//手动创建QLabel 播放gif动画
QLabel* lab2 = new QLabel(this); //加入this相当于在窗体内部显示Label标签,否则将会创建新的窗体
lab2->setGeometry(100, 50, 150, 280);
lab2->setStyleSheet("background-color:rgb(161,200,247);");
lab2->setAlignment(Qt::AlignCenter);
QMovie* mov = new QMovie("R-C.gif");
mov->setScaledSize(QSize(150, 280)); //调整视频界面大小
lab2->setMovie(mov);
//lab2->show(); //在主窗体内部,无需设置,另开窗口需要设置显示
mov->start();
ui.label->setSelection(0,4); //设置label的选中文字
ui.shotPushButton->setShortcut(tr("X")); //设置shotPushButton快捷键方式
ui.shotPushButton->setShortcut(tr("Ctrl+X"));
ui.shotPushButton->setShortcut(tr("Ctrl+X,A")); //先按ctrl+X 然后在按A
ui.lineEdit->setPlaceholderText(QString::fromLocal8Bit("提示输入"));
//lineEdit掩码验证
ui.ipEdit->setInputMask("000.000.000.000;_"); //非强制输入,不输满也可以触发信号
ui.textEdit->setInputMask("AAAAA;_"); //强制输入,必须输满才能触发信号
QIntValidator* ival = new QIntValidator();
ival->setRange(0, 100);
ui.intEdit->setValidator(ival);
QDoubleValidator* dval = new QDoubleValidator();
dval->setRange(0, 1000, 3);
ui.doubleEdit->setValidator(dval); //科学计数法
dval->setNotation(QDoubleValidator::StandardNotation); //使用普通计数法
ui.doubleEdit->setValidator(dval);
QRegExp exp("[a-zA-Z0-9-_]+@[a-zA-Z0-9-_]+\\.[a-zA-Z]+");
QRegExpValidator* rval = new QRegExpValidator(exp);
ui.emailEdit->setValidator(rval);
}