1
0
Fork 0

GUI: format ComboBoxDialog

This commit is contained in:
mrexodia 2017-08-25 13:03:07 +02:00
parent 010a3bbf7e
commit e9d47b0925
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
2 changed files with 130 additions and 130 deletions

View File

@ -1,92 +1,92 @@
#include "ComboBoxDialog.h"
#include "ui_ComboBoxDialog.h"
#include <QLineEdit>
#include <QStringListModel>
#include <QListView>
#include <QCompleter>
ComboBoxDialog::ComboBoxDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ComboBoxDialog)
{
ui->setupUi(this);
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint | Qt::MSWindowsFixedSizeDialogHint);
setModal(true); //modal window
ui->comboBox->setInsertPolicy(QComboBox::NoInsert);
ui->comboBox->setEditable(false);
ui->comboBox->setModel(new QStringListModel(this));
ui->checkBox->hide();
bChecked = false;
ui->label->setVisible(false);
}
ComboBoxDialog::~ComboBoxDialog()
{
delete ui;
}
void ComboBoxDialog::setEditable(bool editable)
{
ui->comboBox->setEditable(editable);
if(editable)
ui->comboBox->completer()->setCompletionMode(QCompleter::PopupCompletion);
}
void ComboBoxDialog::setItems(const QStringList & items)
{
((QStringListModel*)ui->comboBox->model())->setStringList(items);
}
void ComboBoxDialog::setMinimumContentsLength(int characters)
{
ui->comboBox->setMinimumContentsLength(characters);
// For performance reasons use this policy on large models.
ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
}
QString ComboBoxDialog::currentText()
{
return ui->comboBox->currentText();
}
void ComboBoxDialog::setText(const QString & text)
{
if(ui->comboBox->isEditable())
{
ui->comboBox->setEditText(text);
ui->comboBox->lineEdit()->selectAll();
}
else
{
ui->comboBox->setCurrentIndex(ui->comboBox->findText(text));
}
}
void ComboBoxDialog::setPlaceholderText(const QString & text)
{
if(ui->comboBox->isEditable())
ui->comboBox->lineEdit()->setPlaceholderText(text);
}
void ComboBoxDialog::enableCheckBox(bool bEnable)
{
if(bEnable)
ui->checkBox->show();
else
ui->checkBox->hide();
}
void ComboBoxDialog::setCheckBox(bool bSet)
{
ui->checkBox->setChecked(bSet);
bChecked = bSet;
}
void ComboBoxDialog::setCheckBoxText(const QString & text)
{
ui->checkBox->setText(text);
}
void ComboBoxDialog::on_checkBox_toggled(bool checked)
{
bChecked = checked;
}
#include "ComboBoxDialog.h"
#include "ui_ComboBoxDialog.h"
#include <QLineEdit>
#include <QStringListModel>
#include <QListView>
#include <QCompleter>
ComboBoxDialog::ComboBoxDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ComboBoxDialog)
{
ui->setupUi(this);
setModal(true);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint | Qt::MSWindowsFixedSizeDialogHint);
setModal(true); //modal window
ui->comboBox->setInsertPolicy(QComboBox::NoInsert);
ui->comboBox->setEditable(false);
ui->comboBox->setModel(new QStringListModel(this));
ui->checkBox->hide();
bChecked = false;
ui->label->setVisible(false);
}
ComboBoxDialog::~ComboBoxDialog()
{
delete ui;
}
void ComboBoxDialog::setEditable(bool editable)
{
ui->comboBox->setEditable(editable);
if(editable)
ui->comboBox->completer()->setCompletionMode(QCompleter::PopupCompletion);
}
void ComboBoxDialog::setItems(const QStringList & items)
{
((QStringListModel*)ui->comboBox->model())->setStringList(items);
}
void ComboBoxDialog::setMinimumContentsLength(int characters)
{
ui->comboBox->setMinimumContentsLength(characters);
// For performance reasons use this policy on large models.
ui->comboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
}
QString ComboBoxDialog::currentText()
{
return ui->comboBox->currentText();
}
void ComboBoxDialog::setText(const QString & text)
{
if(ui->comboBox->isEditable())
{
ui->comboBox->setEditText(text);
ui->comboBox->lineEdit()->selectAll();
}
else
{
ui->comboBox->setCurrentIndex(ui->comboBox->findText(text));
}
}
void ComboBoxDialog::setPlaceholderText(const QString & text)
{
if(ui->comboBox->isEditable())
ui->comboBox->lineEdit()->setPlaceholderText(text);
}
void ComboBoxDialog::enableCheckBox(bool bEnable)
{
if(bEnable)
ui->checkBox->show();
else
ui->checkBox->hide();
}
void ComboBoxDialog::setCheckBox(bool bSet)
{
ui->checkBox->setChecked(bSet);
bChecked = bSet;
}
void ComboBoxDialog::setCheckBoxText(const QString & text)
{
ui->checkBox->setText(text);
}
void ComboBoxDialog::on_checkBox_toggled(bool checked)
{
bChecked = checked;
}

View File

@ -1,38 +1,38 @@
#ifndef COMBOBOXDIALOG_H
#define COMBOBOXDIALOG_H
#include <QDialog>
namespace Ui
{
class ComboBoxDialog;
}
class ComboBoxDialog : public QDialog
{
Q_OBJECT
public:
explicit ComboBoxDialog(QWidget* parent = 0);
~ComboBoxDialog();
bool bChecked;
QString currentText();
void setEditable(bool editable);
void setItems(const QStringList & items);
// Minimum number of characters that should fit into the combobox.
// Use for large models, so that the length is not computed from its items.
void setMinimumContentsLength(int characters);
void setText(const QString & text);
void setPlaceholderText(const QString & text);
void enableCheckBox(bool bEnable);
void setCheckBox(bool bSet);
void setCheckBoxText(const QString & text);
private slots:
void on_checkBox_toggled(bool checked);
private:
Ui::ComboBoxDialog* ui;
};
#endif // COMBOBOXDIALOG_H
#ifndef COMBOBOXDIALOG_H
#define COMBOBOXDIALOG_H
#include <QDialog>
namespace Ui
{
class ComboBoxDialog;
}
class ComboBoxDialog : public QDialog
{
Q_OBJECT
public:
explicit ComboBoxDialog(QWidget* parent = 0);
~ComboBoxDialog();
bool bChecked;
QString currentText();
void setEditable(bool editable);
void setItems(const QStringList & items);
// Minimum number of characters that should fit into the combobox.
// Use for large models, so that the length is not computed from its items.
void setMinimumContentsLength(int characters);
void setText(const QString & text);
void setPlaceholderText(const QString & text);
void enableCheckBox(bool bEnable);
void setCheckBox(bool bSet);
void setCheckBoxText(const QString & text);
private slots:
void on_checkBox_toggled(bool checked);
private:
Ui::ComboBoxDialog* ui;
};
#endif // COMBOBOXDIALOG_H