From 694466444e0ba07b3d7785d1f608e14f67c975ff Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Thu, 23 Jun 2022 19:15:33 -0400 Subject: [PATCH] Local library: Improvements on QClickableLabel --- locallibrarywidget.cpp | 11 ++++------- qclickablelabel.cpp | 8 +++++++- qclickablelabel.h | 4 +++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/locallibrarywidget.cpp b/locallibrarywidget.cpp index e324dbb..8c1287d 100644 --- a/locallibrarywidget.cpp +++ b/locallibrarywidget.cpp @@ -51,21 +51,18 @@ localLibraryWidget::localLibraryWidget(QWidget *parent) : // Horizontal layout that will contain the book button and its icon QHBoxLayout * horizontalLayout = new QHBoxLayout(this); - // Book icon + // Book icon label bookIconArray[i] = new QLabel(this); + bookIconArray[i]->setStyleSheet("padding: 20px"); // Book button bookBtnArray[i] = new QClickableLabel(this); - bookBtnArray[i]->setProperty("type", "borderless"); - bookIconArray[i]->setStyleSheet("padding: 20px"); + bookBtnArray[i]->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + bookBtnArray[i]->setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 20px"); bookBtnArray[i]->setFont(QFont("u001")); - // Spacer - QSpacerItem * horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); - horizontalLayout->addWidget(bookIconArray[i]); horizontalLayout->addWidget(bookBtnArray[i]); - horizontalLayout->addSpacerItem(horizontalSpacer); ui->booksVerticalLayout->addLayout(horizontalLayout); } setupBooksList(); diff --git a/qclickablelabel.cpp b/qclickablelabel.cpp index 4960700..56630e4 100644 --- a/qclickablelabel.cpp +++ b/qclickablelabel.cpp @@ -7,6 +7,12 @@ QClickableLabel::QClickableLabel(QWidget* parent, Qt::WindowFlags f) QClickableLabel::~QClickableLabel() {} -void QClickableLabel::mousePressEvent(QMouseEvent* event) { +void QClickableLabel::mousePressEvent(QMouseEvent * event) { emit clicked(); + QClickableLabel::setStyleSheet("color: white; background-color: black; border-radius: 10px; padding: 20px"); +} + +void QClickableLabel::mouseReleaseEvent(QMouseEvent * event) { + emit unclicked(); + QClickableLabel::setStyleSheet("color: black; background-color: white; border-radius: 10px; padding: 20px"); } diff --git a/qclickablelabel.h b/qclickablelabel.h index 2d716a9..a921e2a 100644 --- a/qclickablelabel.h +++ b/qclickablelabel.h @@ -14,9 +14,11 @@ public: signals: void clicked(); + void unclicked(); protected: - void mousePressEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent * event); + void mouseReleaseEvent(QMouseEvent * event); };