added a new Dialog it's NameEdit
This commit is contained in:
parent
70ca5d727d
commit
aaac66e4a7
38
inc/hgl/qt/dialog/NameEdit.h
Normal file
38
inc/hgl/qt/dialog/NameEdit.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include<QDialog>
|
||||
#include<QLabel>
|
||||
#include<QLineEdit>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace dialog
|
||||
{
|
||||
class NameEdit:public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
|
||||
QLineEdit *name_edit;
|
||||
|
||||
QLabel *hint_label;
|
||||
|
||||
void OnCancelClicked();
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool OnNameCheck(QString &)=0;
|
||||
|
||||
public:
|
||||
|
||||
NameEdit(const QString &,const QString &);
|
||||
virtual ~NameEdit()=default;
|
||||
|
||||
virtual void OnOKClicked();
|
||||
};//class NameEdit:public QDialog
|
||||
}//namespace dialog
|
||||
}//namespace qt
|
||||
}//namespace hgl
|
@ -11,7 +11,12 @@ ELSEIF()
|
||||
set(CMQT_MAIN_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/QT5UnixUTF8.cpp)
|
||||
endif()
|
||||
|
||||
add_cm_library(CMQT "CM" QT5GuiApplication.cpp)
|
||||
SET(CMQT_DIALOG_FILES ${CMQT_DIALOG_INCLUDE_PATH}/NameEdit.h
|
||||
dialog/NameEdit.cpp)
|
||||
|
||||
SET(CMQT_LIBRARIES CMQT Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
SOURCE_GROUP("Dialog" FILES ${CMQT_DIALOG_FILES})
|
||||
|
||||
add_cm_library(CMQT "CM" ${CMQT_DIALOG_FILES})
|
||||
|
||||
target_link_libraries(CMQT PUBLIC Qt5::Core Qt5::Gui Qt5::Widgets)
|
||||
|
||||
|
89
src/dialog/NameEdit.cpp
Normal file
89
src/dialog/NameEdit.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include<hgl/qt/dialog/NameEdit.h>
|
||||
#include<QVBoxLayout>
|
||||
#include<QPushButton>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace dialog
|
||||
{
|
||||
NameEdit::NameEdit(const QString &hint_text,const QString &str)
|
||||
{
|
||||
setModal(true);
|
||||
|
||||
QVBoxLayout *layout=new QVBoxLayout(this);
|
||||
|
||||
{
|
||||
QLabel *lab=new QLabel(hint_text,this);
|
||||
|
||||
lab->setAlignment(Qt::AlignLeft);
|
||||
|
||||
layout->addWidget(lab);
|
||||
}
|
||||
|
||||
{
|
||||
name_edit=new QLineEdit(str,this);
|
||||
|
||||
name_edit->setAlignment(Qt::AlignCenter);
|
||||
|
||||
name_edit->setCursorPosition(0);
|
||||
|
||||
layout->addWidget(name_edit);
|
||||
}
|
||||
|
||||
{
|
||||
hint_label=new QLabel(this);
|
||||
|
||||
hint_label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
layout->addWidget(hint_label);
|
||||
}
|
||||
|
||||
//按钮区
|
||||
{
|
||||
QWidget *button_widget=new QWidget(this);
|
||||
QHBoxLayout *button_layout=new QHBoxLayout(button_widget);
|
||||
|
||||
//确定、取消按钮
|
||||
{
|
||||
QPushButton *ok_button=new QPushButton(button_widget);
|
||||
ok_button->setText(tr("OK"));
|
||||
connect(ok_button,&QPushButton::clicked,this,&NameEdit::OnOKClicked);
|
||||
|
||||
button_layout->addWidget(ok_button,0,Qt::AlignRight);
|
||||
|
||||
QPushButton *cancel_button=new QPushButton(button_widget);
|
||||
cancel_button->setText(tr("Cancel"));
|
||||
connect(cancel_button,&QPushButton::clicked,this,&NameEdit::OnCancelClicked);
|
||||
|
||||
button_layout->addWidget(cancel_button,0,Qt::AlignLeft);
|
||||
}
|
||||
|
||||
layout->addWidget(button_widget);
|
||||
}
|
||||
|
||||
resize(layout->sizeHint());
|
||||
}
|
||||
|
||||
void NameEdit::OnCancelClicked()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void NameEdit::OnOKClicked()
|
||||
{
|
||||
QString err_text;
|
||||
|
||||
if(OnNameCheck(err_text))
|
||||
close();
|
||||
|
||||
QPalette palette=hint_label->palette();
|
||||
palette.setColor(hint_label->foregroundRole(),Qt::GlobalColor::red);
|
||||
|
||||
hint_label->setPalette(palette);
|
||||
hint_label->setText(err_text);
|
||||
}
|
||||
}//namespace dialog
|
||||
}//namespace qt
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user