Rename Listbox to ListBox, and refactor.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
#include "EditPatientDialog.h"
|
#include "EditPatientDialog.h"
|
||||||
#include "dialogs/SelectDialog.h"
|
#include "dialogs/SelectDialog.h"
|
||||||
#include "DateSelectDialog.h"
|
#include "DateSelectDialog.h"
|
||||||
#include "components/Listbox.h"
|
#include "components/ListBox.h"
|
||||||
|
|
||||||
int queryValue(QSqlTableModel* model, int colID, const QVariant& var)
|
int queryValue(QSqlTableModel* model, int colID, const QVariant& var)
|
||||||
{
|
{
|
||||||
@@ -54,7 +54,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
|
|||||||
QLabel* lbl_sex= new QLabel(this);
|
QLabel* lbl_sex= new QLabel(this);
|
||||||
lbl_sex->setText(tr("Gender"));
|
lbl_sex->setText(tr("Gender"));
|
||||||
layout->addWidget(lbl_sex);
|
layout->addWidget(lbl_sex);
|
||||||
btnSex = new Listbox(this);
|
btnSex = new ListBox(this);
|
||||||
btnSex->setText(tr("Female"));
|
btnSex->setText(tr("Female"));
|
||||||
btnSex->setProperty("idx",0);
|
btnSex->setProperty("idx",0);
|
||||||
btnSex->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
btnSex->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
@@ -87,7 +87,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
|
|||||||
lbl_date->setText(tr("Birth Date"));
|
lbl_date->setText(tr("Birth Date"));
|
||||||
|
|
||||||
layout->addWidget(lbl_date);
|
layout->addWidget(lbl_date);
|
||||||
btnDate = new Listbox(this);
|
btnDate = new ListBox(this);
|
||||||
btnDate->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
btnDate->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
btnDate->setLayoutDirection(Qt::RightToLeft);
|
btnDate->setLayoutDirection(Qt::RightToLeft);
|
||||||
btnDate->setObjectName("editvalBtn");
|
btnDate->setObjectName("editvalBtn");
|
||||||
|
|||||||
27
src/components/ListBox.cpp
Normal file
27
src/components/ListBox.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by Krad on 2022/3/21.
|
||||||
|
//
|
||||||
|
#include "ListBox.h"
|
||||||
|
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QStylePainter>
|
||||||
|
|
||||||
|
ListBox::ListBox(QWidget *parent) : QToolButton(parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ListBox::paintEvent(QPaintEvent *e) {
|
||||||
|
QString temp = this->text();
|
||||||
|
this->setText("");
|
||||||
|
QToolButton::paintEvent(e);
|
||||||
|
this->setText(temp);
|
||||||
|
QStylePainter painter(this);
|
||||||
|
QStyleOptionToolButton opt;
|
||||||
|
initStyleOption(&opt);
|
||||||
|
int x = (size().width() - this->iconSize().width()) / 2 - (this->text().length() * opt.font.pixelSize()) / 4;
|
||||||
|
int y = this->iconSize().height() + 2;
|
||||||
|
painter.drawText(x,y,this->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
22
src/components/ListBox.h
Normal file
22
src/components/ListBox.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Created by Krad on 2022/3/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GUI_LISTBOX_H
|
||||||
|
#define GUI_LISTBOX_H
|
||||||
|
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
|
class ListBox: public QToolButton {
|
||||||
|
public:
|
||||||
|
explicit ListBox(QWidget* parent = nullptr);
|
||||||
|
~ListBox() override = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent* e) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //GUI_LISTBOX_H
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Krad on 2022/3/21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <QtWidgets/qstyleoption.h>
|
|
||||||
#include <QPaintEvent>
|
|
||||||
#include <QStylePainter>
|
|
||||||
#include "Listbox.h"
|
|
||||||
|
|
||||||
void Listbox::paintEvent(QPaintEvent *e) {
|
|
||||||
QString temp = this->text();
|
|
||||||
this->setText("");
|
|
||||||
QToolButton::paintEvent(e);
|
|
||||||
this->setText(temp);
|
|
||||||
QStylePainter p(this);
|
|
||||||
QStyleOptionToolButton opt;
|
|
||||||
initStyleOption(&opt);
|
|
||||||
|
|
||||||
p.drawText((size().width()-this->iconSize().width())/2-(this->text().length()*opt.font.pixelSize())/4,this->iconSize().height()+2,this->text());
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Krad on 2022/3/21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef GUI_LISTBOX_H
|
|
||||||
#define GUI_LISTBOX_H
|
|
||||||
|
|
||||||
#include <QToolButton>
|
|
||||||
class Listbox: public QToolButton {
|
|
||||||
public:
|
|
||||||
explicit Listbox(QWidget* parent = nullptr){};
|
|
||||||
virtual ~Listbox(){};
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void paintEvent(QPaintEvent* e) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif //GUI_LISTBOX_H
|
|
||||||
Reference in New Issue
Block a user