Qt 연습.코드화된 UI 설계
//QWDlgManual.h
#pragma once
#include
#include
#include
#include
#include
#include
#include "ui_QWDlgManual.h"
class QWDlgManual : public QDialog
{
Q_OBJECT
public:
QWDlgManual(QWidget *parent = Q_NULLPTR);
~QWDlgManual();
private slots:
void on_chkBoxUnderline(bool checked);
void on_chkBoxItalic(bool checked);
void on_chkBoxBold(bool checked);
void setTextFontColor();
private:
Ui::QWDlgManualClass ui;
QCheckBox* chkBoxUnder;
QCheckBox* chkBoxItalic;
QCheckBox* chkBoxBold;
QRadioButton* rBtnBlack;
QRadioButton* rBtnRed;
QRadioButton* rBtnBlue;
QPlainTextEdit* txtEdit;
QPushButton* btnOK;
QPushButton* btnCancel;
QPushButton* btnClose;
// ,
void iniUI();
//
void iniSignalSlots();
};
//QWDlgManual.cpp
#include
#include
#include
#include "QWDlgManual.h"
QWDlgManual::QWDlgManual(QWidget *parent)
: QDialog(parent)
{
iniUI();
iniSignalSlots();
setWindowTitle("Keep trying");
}
QWDlgManual::~QWDlgManual()
{
}
void QWDlgManual::on_chkBoxBold(bool checked)
{
QFont font = txtEdit->font();
font.setBold(checked);
txtEdit->setFont(font);
}
void QWDlgManual::on_chkBoxItalic(bool checked)
{
QFont font = txtEdit->font();
font.setItalic(checked);
txtEdit->setFont(font);
}
void QWDlgManual::on_chkBoxUnderline(bool checked)
{
QFont font = txtEdit->font();
font.setUnderline(checked);
txtEdit->setFont(font);
}
void QWDlgManual::setTextFontColor()
{
QPalette plet = txtEdit->palette();
if (rBtnBlack->isChecked())
plet.setColor(QPalette::Text, Qt::black);
else if (rBtnBlue->isChecked())
plet.setColor(QPalette::Text, Qt::blue);
else if (rBtnRed->isChecked())
plet.setColor(QPalette::Text, Qt::red);
else
plet.setColor(QPalette::Text, Qt::black);
txtEdit->setPalette(plet);
}
void QWDlgManual::iniUI()
{
chkBoxBold = new QCheckBox(tr("Bold"));
chkBoxItalic = new QCheckBox(tr("Italic"));
chkBoxUnder = new QCheckBox(tr("Underline"));
QHBoxLayout* HLay1 = new QHBoxLayout;
HLay1->addWidget(chkBoxBold);
HLay1->addWidget(chkBoxItalic);
HLay1->addWidget(chkBoxUnder);
rBtnBlack = new QRadioButton(tr("Black"));
rBtnBlack->setChecked(true);
rBtnBlue = new QRadioButton(tr("Blue"));
rBtnRed = new QRadioButton(tr("Red"));
QHBoxLayout* HLay2 = new QHBoxLayout;
HLay2->addWidget(rBtnBlack);
HLay2->addWidget(rBtnBlue);
HLay2->addWidget(rBtnRed);
btnOK = new QPushButton(tr("OK"));
btnCancel = new QPushButton(tr("Cancel"));
btnClose = new QPushButton(tr("Close"));
QHBoxLayout* HLay3 = new QHBoxLayout;
HLay3->addWidget(btnOK);
HLay3->addWidget(btnClose);
HLay3->addWidget(btnCancel);
txtEdit = new QPlainTextEdit;
txtEdit->setPlainText("Just hold on.
And never give up!");
QFont font = txtEdit->font();
font.setPixelSize(15);
txtEdit->setFont(font);
QVBoxLayout* VLay = new QVBoxLayout;
VLay->addLayout(HLay1);
VLay->addLayout(HLay2);
VLay->addWidget(txtEdit);
VLay->addLayout(HLay3);
setLayout(VLay);
}
void QWDlgManual::iniSignalSlots()
{
connect(rBtnBlue, SIGNAL(clicked()), this, SLOT(setTextFontColor()));
connect(rBtnBlack, SIGNAL(clicked()), this, SLOT(setTextFontColor()));
connect(rBtnRed, SIGNAL(clicked()), this, SLOT(setTextFontColor()));
connect(chkBoxBold, SIGNAL(clicked(bool)), this, SLOT(on_chkBoxBold(bool)));
connect(chkBoxUnder, SIGNAL(clicked(bool)), this, SLOT(on_chkBoxUnderline(bool)));
connect(chkBoxItalic, SIGNAL(clicked(bool)), this, SLOT(on_chkBoxItalic(bool)));
connect(btnOK, SIGNAL(clicked()), this, SLOT(accept()));
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(btnClose, SIGNAL(clicked()), this, SLOT(close()));
}
//main.cpp
#include "QWDlgManual.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWDlgManual w;
w.show();
return a.exec();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Qt 연습.코드화된 UI 설계텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.