019/PyQt5
/PyQt5/PyQt5/PyQt5/Qt/Gui/qwidget.cpp
#include "QDialog.h"
QDialog::QDialog(QWidget *parent) : QWidget(parent), m_isOpen(true)
{
m_button = new QPushButton("关闭", this);
m_label = new QLabel("这是一个测试窗口", this);
m_label->setGeometry(100, 100, 100, 30);
m_button->setGeometry(200, 100, 100, 30);
connect(m_button, SIGNAL(clicked()), this, SLOT(close()));
connect(m_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
QDialog::~QDialog()
{
if (m_isOpen)
{
close();
}
}
void QDialog::close()
{
m_isOpen = false;
}
void QDialog::onButtonClicked()
{
QMessageBox::information(this, "提示", "你点了关闭按钮!");
}
/PyQt5/PyQt5/PyQt5/Qt/Gui/qtextedit.cpp
#include "QTextEdit.h"
QTextEdit::QTextEdit(QWidget *parent) : QWidget(parent)
{
// 创建一个 QTextEdit 对象
m_textEdit = new QTextEdit(parent);
// 创建一个 QTextEdit 编辑框
m_textEdit->setGeometry(10, 10, 200, 100);
// 创建一个 QTextEdit 标签
m_label = new QLabel("这是一个 QTextEdit 编辑框", this);
// 将 QTextEdit 编辑框���标签添加到布局中
m_layout = new QVBoxLayout();
m_layout->addWidget(m_label);
m_layout->addWidget(m_textEdit);
// 将布局设置为 QWidget 的布局
setLayout(m_layout);
}
QTextEdit::~QTextEdit()
{
// 如果 QTextEdit 对象还在使用,需要将其删除
if (m_textEdit != nullptr)
{
delete m_textEdit;
}
}
/PyQt5/PyQt5/PyQt5/Qt/Widgets/qabstractscrollarea.cpp
#include "QTabBar.h"
QTabBar::QTabBar(QWidget *parent)
: QWidget(parent)
{
m_label = new QLabel("Tab Bar", this);
m_label->setGeometry(10, 10, 100, 30);
m_label->setAlignment(Qt::AlignCenter);
m_button = new QPushButton("关闭", this);
m_button->setGeometry(200, 100, 100, 30);
connect(m_button, SIGNAL(clicked()), this, SLOT(close()));
m_layout = new QVBoxLayout();
m_layout->addWidget(m_label);
m_layout->addWidget(m_button);
setLayout(m_layout);
// 添加一个槽函数到 tab 关闭按钮
connect(m_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
QTabBar::~QTabBar()
{
// 如果 tab 关闭按钮还在使用,需要将其删除
if (m_button != nullptr)
{
delete m_button;
}
}
void QTabBar::onButtonClicked()
{
QMessageBox::information(this, "提示", "你点了关闭按钮!");
}
/PyQt5/PyQt5/PyQt5/Qt/Gui/qlineedit.cpp
#include "QLineEdit.h"
QLineEdit::QLineEdit(QWidget *parent) : QWidget(parent)
{
m_lineEdit = new QLineEdit(parent);
m_lineEdit->setGeometry(50, 50, 200, 30);
}
QLineEdit::~QLineEdit()
{
if (m_lineEdit != nullptr)
{
delete m_lineEdit;
}
}
/PyQt5/PyQt5/PyQt5/Qt/Gui/qapplication.cpp
#include "QApplication.h"
QApplication::QApplication(int &argc, char **argv)
: QLibrary(QLibraryName::All, nullptr)
{
setApplicationName("PyQt5 Application");
setApplicationVersion("1.0");
setOrganizationName("PyQt5");
setOrganizationDomain("www.pyqt5.com");
setLibraryDirectory(QStandardPaths::writableLocation(QStandardPaths::LibraryLocation));
}
QApplication::~QApplication()
{
}
bool QApplication::notify(QObject *object, QEvent *event)
{
return QCoreApplication::notify(object, event);
}
QEventLoop &QApplication::startEventLoop()
{
return QCoreApplication::startEventLoop();
}
/PyQt5/PyQt5/PyQt5/Qt/Gui/qlineedit.h
#ifndef QLINEEDIT_H
#define QLINEEDIT_H
#include <QWidget>
#include <QLineEdit>
class QLineEdit : public QWidget
{
public:
QLineEdit(QWidget *parent = nullptr);
~QLineEdit();
private:
QLineEdit *m_lineEdit;
};
#endif // QLINEEDIT_H
/PyQt5/PyQt5/PyQt5/Qt/Gui/qtextbrowser.cpp
#include "QTextEdit.h"
QTextEdit::QTextEdit(QWidget *parent) : QWidget(parent)
{
// 创建一个 QTextEdit 对象
m_textEdit = new QTextEdit(parent);
// 创建一个 QTextEdit 编辑框
m_textEdit->setGeometry(10, 10, 200, 100);
// 创建一个 QTextEdit 标签
m_label = new QLabel("这是一个 QTextEdit 编辑框", this);
// 将 QTextEdit 编辑框和标签添加到布局中
m_layout = new QVBoxLayout();