QT 인터페이스 프로그래밍 지식
0. QT 패키지 고려 사항
1. 신호와 슬롯
/* :
1. , Qt signals public,private, protected。
2. , void。
3. 。
4. QOBject , Q_OBJECT。
5. , , , , , , 。
6. , : , , 。
7. emit 。
8. 。
*/
/* :
1. C++ , 。 , 。
2. :public/protected/private slots:
3. Qt4 , Qt5 , , Lambda 。 , .
*/
connect(pushButton, SIGNAL(clicked()), dialog, SLOT(close()));
connect(pushButton, QPushButton::clicked, dialog, QDialog::close);
#include "widget.h"
#include
#include
#include
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
vLayout = new QVBoxLayout(this);
b1=new QPushButton(" ",this);
b2=new QPushButton(" ",this);
b3=new QPushButton(" ",this);
vLayout->addWidget(b1);
vLayout->addWidget(b2);
vLayout->addWidget(b3);
connect(b1,&QPushButton::clicked,[=](){this->close();});
}
Widget::~Widget()
{}
//
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QPushButton *b1;
private slots:
void on_button1_released();
};
#endif // WIDGET_H
//
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
resize(500,300);
b1=new QPushButton("CLOSE",this);
b1->move(200,200);
b1->setObjectName(QStringLiteral("button1"));
QMetaObject::connectSlotsByName(this);
}
Widget::~Widget()
{}
void Widget::on_button1_released()
{
this->close();
}
//
b1->setObjectName(QStringLiteral("button1")); //
QMetaObject::connectSlotsByName(this); //
void Widget::on_button1_released(); // ,
#include "widget.h"
#include
#include
#include
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
// ,
QVBoxLayout* vLayout = new QVBoxLayout(this);
// , ,
QLineEdit* edit = new QLineEdit;
edit->setAlignment(Qt::AlignRight);
vLayout->addWidget(edit);//
//
QSignalMapper* signalMapper = new QSignalMapper(this);
// 0-9 ,
QGridLayout *gridLayout = new QGridLayout;
for (int i = 0; i < 10; ++i)
{
QString txt = QString::number(i);
QPushButton *button = new QPushButton(txt);
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, txt);//
gridLayout->addWidget(button, i / 3, i % 3);// 3
}
//
connect(signalMapper, SIGNAL(mapped(QString)),
edit, SLOT(setText(QString)));
vLayout->addLayout(gridLayout);
resize(200, 200);
}
Widget::~Widget()
{}
// :
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, txt);//
connect(signalMapper, SIGNAL(mapped(QString)),edit, SLOT(setText(QString)));
2. 모드 대화 상자 및 비모드 대화 상자 #include "widget.h"
#include
#include
#include
#include
#include "customdialog.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
vLayout = new QVBoxLayout(this);
b1=new QPushButton(" ",this);
b2=new QPushButton(" ",this);
b3=new QPushButton(" ",this);
vLayout->addWidget(b1);
vLayout->addWidget(b2);
vLayout->addWidget(b3);
connect(b1,&QPushButton::clicked,[=](){
//
QDialog* dlg = new QDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);// ,
dlg->setWindowModality(Qt::WindowModal);// setModel(true)
dlg->show();
});
connect(b2,&QPushButton::clicked,[=](){
//
QDialog *modellessDig=new QDialog;
modellessDig->setWindowTitle(" ");
modellessDig->setAttribute(Qt::WA_DeleteOnClose);
modellessDig->show();
});
connect(b3,&QPushButton::clicked,[=](){
//
CustomDialog *dlg=new CustomDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
int ret = dlg->exec();
if (ret == QDialog::Accepted)
{
qDebug()<
3. 표준 대화상자 //
int i = QInputDialog::getInt(this, tr(" "),tr(" "), 25, 16, 100, 1, &ok);
double d = QInputDialog::getDouble(this, tr(" "),tr(" "), 1000, 100, 10000, 1, &ok);
QStringList items;
items << tr(" ") << tr("Dota") << tr("Dota2") << tr("LOL");
bool ok;
QString item = QInputDialog::getItem(this, tr(" "),tr(" "), items, 0, false, &ok);
QString text = QInputDialog::getText(this, tr(" "),tr(" "), QLineEdit::Normal,tr(" "), &ok);
QString text = QInputDialog::getMultiLineText(this, tr(" "),tr(" "), " ", &ok);
//
QColor color = QColorDialog::getColor(Qt::green, this, " ", QColorDialog::DontUseNativeDialog);
//
QFont font =QFontDialog::getFont(&ok,this);
// :
QString directory = QFileDialog::getExistingDirectory(this,"Get directory:","./");
//
QString fileName = QFileDialog::getOpenFileName(this,"Open a file","./","All Files (*);;Text Files (*.txt)");
//
QStringList files = QFileDialog::getOpenFileNames(this,"Open multiple files:","./","All Files (*);;Text Files (*.txt)");
//
QString fileName = QFileDialog::getSaveFileName(this,tr("Save file:"),"./",tr("All Files (*);;Text Files (*.txt)"));
//
qDebug()<<:critical qdebug="" you="" no="" or="" that="" qmessagebox::no="" qmessagebox::cancel=""/>
4. 템플릿 클래스 및 도구 클래스 QString
QList
QLinkedList
QVector
QMap
QHash
QVariable
5. 창 배치
(1) QSplitter
QSplitter 소형 인스턴스//
QSplitter *splitterMain = new QSplitter(Qt::Horizontal, Q_NULLPTR);
QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget"),splitterMain);
QTextEdit *textRight = new QTextEdit(QObject::tr("Right Widget"), splitterMain);
QTextEdit *textRight2 = new QTextEdit(QObject::tr("Right Widget2"), splitterMain);
splitterMain->setStretchFactor(1, 1);
splitterMain->setWindowTitle(QObject::tr("Splitter"));
splitterMain->show();
// QSplitter QWidget
//setStretchFactor(int index,int factor) :
//
splitterMain->setStretchFactor(0, 1);
splitterMain->setStretchFactor(1, 3);
splitterMain->setStretchFactor(2, 3);
//factor , 0 , 0
(2) QDockWidget
setWindowTitle(" ");
QTextEdit *te = new QTextEdit(this);
te->setText("Main Window");
te->setAlignment(Qt::AlignCenter);
setCentralWidget(te);
QDockWidget *dock1 = new QDockWidget(" 1", this);
dock1->setFeatures(QDockWidget::DockWidgetMovable);
dock1->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QTextEdit *te1 = new QTextEdit();
te1->setText("dock1, which can be moded to left or right side");
dock1->setWidget(te1);
addDockWidget(Qt::RightDockWidgetArea, dock1);
QDockWidget *dock2 = new QDockWidget(" 2", this);
dock2->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
QTextEdit *te2 = new QTextEdit();
te2->setText("dock2, which can be closed and floated");
dock2->setWidget(te2);
addDockWidget(Qt::RightDockWidgetArea, dock2);
QDockWidget *dock3 = new QDockWidget(" 3", this);
dock3->setFeatures(QDockWidget::AllDockWidgetFeatures);
QTextEdit *te3 = new QTextEdit();
te3->setText("dock3, all features");
dock3->setWidget(te3);
addDockWidget(Qt::RightDockWidgetArea, dock3);
(3) QStackedWidget
label1 = new QLabel("WindowTest1");
label2 = new QLabel("WindowTest2");
label3 = new QLabel("WindowTest3");
widget = new MyWidget();
stack = new QStackedWidget(this);
stack->addWidget(label1);
stack->addWidget(label2);
stack->addWidget(label3);
stack->addWidget(widget);
stack->setCurrentIndex(1);
(4) 3가지 기본 레이아웃
QHBoxLayout
QVBoxLayout
QGridLayout
6. 중국어 난자 문제
참고 자료
#include "widget.h"
#include
#include
#include
#include
#include "customdialog.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
vLayout = new QVBoxLayout(this);
b1=new QPushButton(" ",this);
b2=new QPushButton(" ",this);
b3=new QPushButton(" ",this);
vLayout->addWidget(b1);
vLayout->addWidget(b2);
vLayout->addWidget(b3);
connect(b1,&QPushButton::clicked,[=](){
//
QDialog* dlg = new QDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);// ,
dlg->setWindowModality(Qt::WindowModal);// setModel(true)
dlg->show();
});
connect(b2,&QPushButton::clicked,[=](){
//
QDialog *modellessDig=new QDialog;
modellessDig->setWindowTitle(" ");
modellessDig->setAttribute(Qt::WA_DeleteOnClose);
modellessDig->show();
});
connect(b3,&QPushButton::clicked,[=](){
//
CustomDialog *dlg=new CustomDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
int ret = dlg->exec();
if (ret == QDialog::Accepted)
{
qDebug()<
//
int i = QInputDialog::getInt(this, tr(" "),tr(" "), 25, 16, 100, 1, &ok);
double d = QInputDialog::getDouble(this, tr(" "),tr(" "), 1000, 100, 10000, 1, &ok);
QStringList items;
items << tr(" ") << tr("Dota") << tr("Dota2") << tr("LOL");
bool ok;
QString item = QInputDialog::getItem(this, tr(" "),tr(" "), items, 0, false, &ok);
QString text = QInputDialog::getText(this, tr(" "),tr(" "), QLineEdit::Normal,tr(" "), &ok);
QString text = QInputDialog::getMultiLineText(this, tr(" "),tr(" "), " ", &ok);
//
QColor color = QColorDialog::getColor(Qt::green, this, " ", QColorDialog::DontUseNativeDialog);
//
QFont font =QFontDialog::getFont(&ok,this);
// :
QString directory = QFileDialog::getExistingDirectory(this,"Get directory:","./");
//
QString fileName = QFileDialog::getOpenFileName(this,"Open a file","./","All Files (*);;Text Files (*.txt)");
//
QStringList files = QFileDialog::getOpenFileNames(this,"Open multiple files:","./","All Files (*);;Text Files (*.txt)");
//
QString fileName = QFileDialog::getSaveFileName(this,tr("Save file:"),"./",tr("All Files (*);;Text Files (*.txt)"));
//
qDebug()<<:critical qdebug="" you="" no="" or="" that="" qmessagebox::no="" qmessagebox::cancel=""/>
4. 템플릿 클래스 및 도구 클래스 QString
QList
QLinkedList
QVector
QMap
QHash
QVariable
5. 창 배치
(1) QSplitter
QSplitter 소형 인스턴스//
QSplitter *splitterMain = new QSplitter(Qt::Horizontal, Q_NULLPTR);
QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget"),splitterMain);
QTextEdit *textRight = new QTextEdit(QObject::tr("Right Widget"), splitterMain);
QTextEdit *textRight2 = new QTextEdit(QObject::tr("Right Widget2"), splitterMain);
splitterMain->setStretchFactor(1, 1);
splitterMain->setWindowTitle(QObject::tr("Splitter"));
splitterMain->show();
// QSplitter QWidget
//setStretchFactor(int index,int factor) :
//
splitterMain->setStretchFactor(0, 1);
splitterMain->setStretchFactor(1, 3);
splitterMain->setStretchFactor(2, 3);
//factor , 0 , 0
(2) QDockWidget
setWindowTitle(" ");
QTextEdit *te = new QTextEdit(this);
te->setText("Main Window");
te->setAlignment(Qt::AlignCenter);
setCentralWidget(te);
QDockWidget *dock1 = new QDockWidget(" 1", this);
dock1->setFeatures(QDockWidget::DockWidgetMovable);
dock1->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QTextEdit *te1 = new QTextEdit();
te1->setText("dock1, which can be moded to left or right side");
dock1->setWidget(te1);
addDockWidget(Qt::RightDockWidgetArea, dock1);
QDockWidget *dock2 = new QDockWidget(" 2", this);
dock2->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
QTextEdit *te2 = new QTextEdit();
te2->setText("dock2, which can be closed and floated");
dock2->setWidget(te2);
addDockWidget(Qt::RightDockWidgetArea, dock2);
QDockWidget *dock3 = new QDockWidget(" 3", this);
dock3->setFeatures(QDockWidget::AllDockWidgetFeatures);
QTextEdit *te3 = new QTextEdit();
te3->setText("dock3, all features");
dock3->setWidget(te3);
addDockWidget(Qt::RightDockWidgetArea, dock3);
(3) QStackedWidget
label1 = new QLabel("WindowTest1");
label2 = new QLabel("WindowTest2");
label3 = new QLabel("WindowTest3");
widget = new MyWidget();
stack = new QStackedWidget(this);
stack->addWidget(label1);
stack->addWidget(label2);
stack->addWidget(label3);
stack->addWidget(widget);
stack->setCurrentIndex(1);
(4) 3가지 기본 레이아웃
QHBoxLayout
QVBoxLayout
QGridLayout
6. 중국어 난자 문제
참고 자료
QString
QList
QLinkedList
QVector
QMap
QHash
QVariable
(1) QSplitter
QSplitter 소형 인스턴스
//
QSplitter *splitterMain = new QSplitter(Qt::Horizontal, Q_NULLPTR);
QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget"),splitterMain);
QTextEdit *textRight = new QTextEdit(QObject::tr("Right Widget"), splitterMain);
QTextEdit *textRight2 = new QTextEdit(QObject::tr("Right Widget2"), splitterMain);
splitterMain->setStretchFactor(1, 1);
splitterMain->setWindowTitle(QObject::tr("Splitter"));
splitterMain->show();
// QSplitter QWidget
//setStretchFactor(int index,int factor) :
//
splitterMain->setStretchFactor(0, 1);
splitterMain->setStretchFactor(1, 3);
splitterMain->setStretchFactor(2, 3);
//factor , 0 , 0
(2) QDockWidget
setWindowTitle(" ");
QTextEdit *te = new QTextEdit(this);
te->setText("Main Window");
te->setAlignment(Qt::AlignCenter);
setCentralWidget(te);
QDockWidget *dock1 = new QDockWidget(" 1", this);
dock1->setFeatures(QDockWidget::DockWidgetMovable);
dock1->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
QTextEdit *te1 = new QTextEdit();
te1->setText("dock1, which can be moded to left or right side");
dock1->setWidget(te1);
addDockWidget(Qt::RightDockWidgetArea, dock1);
QDockWidget *dock2 = new QDockWidget(" 2", this);
dock2->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable);
QTextEdit *te2 = new QTextEdit();
te2->setText("dock2, which can be closed and floated");
dock2->setWidget(te2);
addDockWidget(Qt::RightDockWidgetArea, dock2);
QDockWidget *dock3 = new QDockWidget(" 3", this);
dock3->setFeatures(QDockWidget::AllDockWidgetFeatures);
QTextEdit *te3 = new QTextEdit();
te3->setText("dock3, all features");
dock3->setWidget(te3);
addDockWidget(Qt::RightDockWidgetArea, dock3);
(3) QStackedWidget
label1 = new QLabel("WindowTest1");
label2 = new QLabel("WindowTest2");
label3 = new QLabel("WindowTest3");
widget = new MyWidget();
stack = new QStackedWidget(this);
stack->addWidget(label1);
stack->addWidget(label2);
stack->addWidget(label3);
stack->addWidget(widget);
stack->setCurrentIndex(1);
(4) 3가지 기본 레이아웃
QHBoxLayout
QVBoxLayout
QGridLayout
6. 중국어 난자 문제
참고 자료
pragma execution_character_set("utf-8")이 제일 좋아요.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.