Created custom PushButton widget and added custom styleName property for styling primary buttons

This commit is contained in:
Nav
2022-12-21 15:39:18 +00:00
parent fc883d5d1e
commit 47b9c53033
13 changed files with 80 additions and 33 deletions

View File

@@ -199,3 +199,8 @@ Bloom--Widgets--SvgToolButton QMenu::item {
padding-left: 10px;
min-width: 250px;
}
Bloom--Widgets--PushButton[styleName="primary"] {
background-color: #353C41;
border: 1px solid #454C52;
}

View File

@@ -7,6 +7,7 @@
#include "Widgets/RotatableLabel.hpp"
#include "Widgets/LabeledSeparator.hpp"
#include "Widgets/TextInput.hpp"
#include "Widgets/PushButton.hpp"
#include "Widgets/SvgWidget.hpp"
#include "Widgets/SvgToolButton.hpp"
#include "Widgets/ExpandingHeightScrollAreaWidget.hpp"
@@ -54,6 +55,15 @@ namespace Bloom
return widget;
}
},
{
"PushButton",
[this] (QWidget* parent, const QString& name) {
auto* widget = new PushButton(parent);
widget->setObjectName(name);
widget->setStyleSheet(parent->styleSheet());
return widget;
}
},
{
"ExpandingHeightScrollAreaWidget",
[this] (QWidget* parent, const QString& name) {

View File

@@ -0,0 +1,8 @@
#include "PushButton.hpp"
namespace Bloom::Widgets
{
PushButton::PushButton(QWidget* parent)
: QPushButton(parent)
{}
}

View File

@@ -0,0 +1,27 @@
#pragma once
#include <QPushButton>
#include <QString>
namespace Bloom::Widgets
{
class PushButton: public QPushButton
{
Q_OBJECT
Q_PROPERTY(QString styleName READ getStyleName WRITE setStyleName DESIGNABLE true)
public:
explicit PushButton(QWidget* parent = nullptr);
void setStyleName(const QString& styleName) {
this->styleName = styleName;
}
[[nodiscard]] QString getStyleName() const {
return this->styleName;
}
protected:
QString styleName;
};
}

View File

@@ -77,9 +77,9 @@ namespace Bloom::Widgets
this->stackedFormLayout = this->container->findChild<QStackedLayout*>("stacked-form-layout");
this->applyButton = this->container->findChild<QPushButton*>("apply-btn");
this->helpButton = this->container->findChild<QPushButton*>("help-btn");
this->closeButton = this->container->findChild<QPushButton*>("close-btn");
this->applyButton = this->container->findChild<PushButton*>("apply-btn");
this->helpButton = this->container->findChild<PushButton*>("help-btn");
this->closeButton = this->container->findChild<PushButton*>("close-btn");
regionSelectorToolBar->setContentsMargins(0, 0, 0, 0);
this->regionItemScrollArea->setContentsMargins(0, 0, 0, 0);

View File

@@ -1,7 +1,6 @@
#pragma once
#include <QWidget>
#include <QPushButton>
#include <set>
#include <vector>
#include <QShowEvent>
@@ -17,6 +16,7 @@
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/ExcludedMemoryRegion.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PushButton.hpp"
#include "RegionItem.hpp"
#include "FocusedRegionItem.hpp"
#include "ExcludedRegionItem.hpp"
@@ -51,9 +51,9 @@ namespace Bloom::Widgets
QWidget* container = nullptr;
QWidget* regionSelector = nullptr;
QPushButton* applyButton = nullptr;
QPushButton* helpButton = nullptr;
QPushButton* closeButton = nullptr;
PushButton* applyButton = nullptr;
PushButton* helpButton = nullptr;
PushButton* closeButton = nullptr;
SvgToolButton* addRegionButton = nullptr;
QAction* addFocusedRegionMenuAction = nullptr;

View File

@@ -130,8 +130,3 @@
border-top: 1px solid #2F2F2D;
min-height: 50px;
}
#apply-btn {
background-color: #353C41;
border: 1px solid #454C52;
}

View File

@@ -200,7 +200,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="help-btn">
<widget class="PushButton" name="help-btn">
<property name="text">
<string>Help</string>
</property>
@@ -214,14 +214,17 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="close-btn">
<widget class="PushButton" name="close-btn">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="apply-btn">
<widget class="PushButton" name="apply-btn">
<property name="styleName">
<string>primary</string>
</property>
<property name="text">
<string>OK</string>
</property>

View File

@@ -28,11 +28,6 @@
max-width: 500px;
}
#apply-btn {
background-color: #353C41;
border: 1px solid #454C52;
}
/* BitsetWidget */
#bitset-widget {
font-size: 12px;

View File

@@ -81,10 +81,10 @@ namespace Bloom::Widgets
this->registerValueBitsetWidgetContainer = this->registerValueContainer->findChild<QWidget*>(
"register-value-bitset-widget-container"
);
this->refreshValueButton = this->container->findChild<QPushButton*>("refresh-value-btn");
this->applyButton = this->container->findChild<QPushButton*>("apply-btn");
this->helpButton = this->container->findChild<QPushButton*>("help-btn");
this->closeButton = this->container->findChild<QPushButton*>("close-btn");
this->refreshValueButton = this->container->findChild<PushButton*>("refresh-value-btn");
this->applyButton = this->container->findChild<PushButton*>("apply-btn");
this->helpButton = this->container->findChild<PushButton*>("help-btn");
this->closeButton = this->container->findChild<PushButton*>("close-btn");
this->registerHistoryWidget = new RegisterHistoryWidget(
this->registerDescriptor,

View File

@@ -2,7 +2,6 @@
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <set>
#include <QSize>
#include <QString>
@@ -14,6 +13,7 @@
#include "src/Targets/TargetState.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/Label.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/Widgets/PushButton.hpp"
#include "BitsetWidget/BitsetWidget.hpp"
#include "RegisterHistoryWidget/RegisterHistoryWidget.hpp"
@@ -54,10 +54,10 @@ namespace Bloom::Widgets
QWidget* registerValueBitsetWidgetContainer = nullptr;
std::vector<BitsetWidget*> bitsetWidgets;
QPushButton* refreshValueButton = nullptr;
QPushButton* applyButton = nullptr;
QPushButton* helpButton = nullptr;
QPushButton* closeButton = nullptr;
PushButton* refreshValueButton = nullptr;
PushButton* applyButton = nullptr;
PushButton* helpButton = nullptr;
PushButton* closeButton = nullptr;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;

View File

@@ -330,7 +330,7 @@
<number>15</number>
</property>
<item alignment="Qt::AlignCenter">
<widget class="QPushButton" name="refresh-value-btn">
<widget class="PushButton" name="refresh-value-btn">
<property name="text">
<string>Refresh Value</string>
</property>
@@ -344,7 +344,10 @@
</spacer>
</item>
<item alignment="Qt::AlignCenter">
<widget class="QPushButton" name="apply-btn">
<widget class="PushButton" name="apply-btn">
<property name="styleName">
<string>primary</string>
</property>
<property name="text">
<string>Write Value</string>
</property>
@@ -414,7 +417,7 @@
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="help-btn">
<widget class="PushButton" name="help-btn">
<property name="text">
<string>Help</string>
</property>
@@ -428,7 +431,7 @@
</spacer>
</item>
<item alignment="Qt::AlignRight">
<widget class="QPushButton" name="close-btn">
<widget class="PushButton" name="close-btn">
<property name="text">
<string>Close</string>
</property>