mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 06:20:53 +01:00
Added padding variables for ColorButton and ColorComboBoxDelegate
This commit is contained in:
@@ -73,6 +73,11 @@ void ColorButton::clicked(bool checked)
|
|||||||
*/
|
*/
|
||||||
void ColorButton::paintEvent(QPaintEvent *e) {
|
void ColorButton::paintEvent(QPaintEvent *e) {
|
||||||
QPushButton::paintEvent(e);
|
QPushButton::paintEvent(e);
|
||||||
|
|
||||||
|
// Padding for the color indicator
|
||||||
|
const int padding_x = 5;
|
||||||
|
const int padding_y = 5;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
// Get dimensions of the button paint surface
|
// Get dimensions of the button paint surface
|
||||||
@@ -80,6 +85,6 @@ void ColorButton::paintEvent(QPaintEvent *e) {
|
|||||||
auto r_height = painter.device()->height();
|
auto r_height = painter.device()->height();
|
||||||
|
|
||||||
// Paint a rectangle with a margin of 5
|
// Paint a rectangle with a margin of 5
|
||||||
auto color_indicator = QRect(5, 5, r_width - 10, r_height - 10);
|
auto color_indicator = QRect(padding_x, padding_y, r_width - padding_x * 2, r_height - padding_y * 2);
|
||||||
painter.fillRect(color_indicator, m_color);
|
painter.fillRect(color_indicator, m_color);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
*/
|
*/
|
||||||
void ColorComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
void ColorComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
|
// Padding for the color indicator
|
||||||
|
const int padding_x = 5;
|
||||||
|
const int padding_y = 2;
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
if (index.row() > 0)
|
if (index.row() > 0)
|
||||||
@@ -47,7 +51,7 @@ void ColorComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|||||||
|
|
||||||
// Draw color indicator rectangle
|
// Draw color indicator rectangle
|
||||||
auto color = qvariant_cast<QColor>(index.data());
|
auto color = qvariant_cast<QColor>(index.data());
|
||||||
rect.adjust(5, 2, -5, -2);
|
rect.adjust(padding_x, padding_y, -padding_x, -padding_y);
|
||||||
painter->fillRect(rect, color);
|
painter->fillRect(rect, color);
|
||||||
} else {
|
} else {
|
||||||
// Draw a normal drop down item for custom color
|
// Draw a normal drop down item for custom color
|
||||||
|
|||||||
Reference in New Issue
Block a user