Created
February 7, 2018 01:33
-
-
Save jniemann66/67736a57457af2998f6eb2d51a82513f to your computer and use it in GitHub Desktop.
Qt Generic Multiline Text Edit Dialog Boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "multilinetextdialog.h" | |
| #include <QVBoxLayout> | |
| #include <QDialogButtonBox> | |
| #include <QPushButton> | |
| MultilineTextDialog::MultilineTextDialog(QWidget *parent) : QDialog(parent) | |
| { | |
| // allocate widgets | |
| heading = new QLabel; | |
| textEdit = new QTextEdit(this); | |
| auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Reset | QDialogButtonBox::Save | QDialogButtonBox::Cancel); | |
| // allocate layouts | |
| QVBoxLayout* mainLayout = new QVBoxLayout; | |
| // attach | |
| mainLayout->addWidget(heading); | |
| mainLayout->addWidget(textEdit); | |
| mainLayout->addWidget(buttonBox); | |
| setLayout(mainLayout); | |
| // connect signals / slots | |
| connect(buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked, [this] { | |
| textEdit->clear(); | |
| }); | |
| connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); | |
| connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); | |
| } | |
| QTextEdit *MultilineTextDialog::getTextEdit() const | |
| { | |
| return textEdit; | |
| } | |
| void MultilineTextDialog::setText(const QString &text) | |
| { | |
| textEdit->setText(text); | |
| } | |
| QString MultilineTextDialog::getText() const | |
| { | |
| return textEdit->toPlainText(); | |
| } | |
| void MultilineTextDialog::setHeading(const QString& text) { | |
| heading->setText(text); | |
| QFont font(this->font()); | |
| font.setBold(true); | |
| font.setPointSize(font.pointSize() + 2); | |
| heading->setFont(font); | |
| heading->setAlignment(Qt::AlignCenter); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef MULTILINETEXTDIALOG_H | |
| #define MULTILINETEXTDIALOG_H | |
| #include <QDialog> | |
| #include <QTextEdit> | |
| #include <QLabel> | |
| class MultilineTextDialog : public QDialog | |
| { | |
| public: | |
| MultilineTextDialog(QWidget* parent = 0); | |
| QTextEdit *getTextEdit() const; | |
| QString getText() const; | |
| void setText(const QString& text); | |
| void setHeading(const QString &heading); | |
| private: | |
| QTextEdit* textEdit; | |
| QLabel* heading; | |
| }; | |
| #endif // MULTILINETEXTDIALOG_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment