mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Fixed widget rendering issues
This commit is contained in:
parent
a9668ca86e
commit
4cf027df58
@ -30,20 +30,20 @@ void ColorBox::paintEvent(QPaintEvent *event)
|
||||
QStylePainter painter(this);
|
||||
|
||||
QStyleOptionComboBox option;
|
||||
option.initFrom(this);
|
||||
option.initFrom(this);
|
||||
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN32)
|
||||
painter.setBrush(_color);
|
||||
painter.drawPrimitive(QStyle::PE_Frame, option);
|
||||
#else // Q_OS_MAC || Q_OS_WIN32
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
// Fallback for some broken QT4 styles that do not draw the background
|
||||
painter.setBrush(_color);
|
||||
painter.drawRect(event->rect().adjusted(-1, -1, 0, 0));
|
||||
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
|
||||
#else // QT 5
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.drawRect(event->rect().adjusted(2, 2, -2, -2));
|
||||
// If works (QT5 and most QT4 styles) overpaints the previous rectangle
|
||||
option.palette.setBrush(QPalette::Base, _color);
|
||||
painter.drawPrimitive(QStyle::PE_PanelLineEdit, option);
|
||||
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
|
||||
#endif // QT 5
|
||||
#endif // Q_OS_MAC || Q_OS_WIN32
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,10 @@
|
||||
#include <QResizeEvent>
|
||||
#include "stylecombobox.h"
|
||||
|
||||
|
||||
#define MIN_LINE_LENGTH 50
|
||||
#define LINE_WIDTH_RATIO 7
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
||||
|
||||
StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
||||
@ -11,7 +15,7 @@ StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
||||
Qt::DashDotLine, Qt::DashDotDotLine};
|
||||
|
||||
QSize is = iconSize();
|
||||
setIconSize(QSize(sizeHint().width(), is.height()));
|
||||
setIconSize(QSize(MIN_LINE_LENGTH, is.height()));
|
||||
is = iconSize();
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(styles); i++) {
|
||||
@ -19,7 +23,7 @@ StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
||||
pm.fill(Qt::transparent);
|
||||
|
||||
QBrush brush(Qt::black);
|
||||
QPen pen(brush, is.height() / 7, styles[i]);
|
||||
QPen pen(brush, is.height() / LINE_WIDTH_RATIO, styles[i]);
|
||||
|
||||
QPainter painter(&pm);
|
||||
painter.setPen(pen);
|
||||
@ -42,7 +46,8 @@ void StyleComboBox::setValue(Qt::PenStyle value)
|
||||
void StyleComboBox::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QSize is = iconSize();
|
||||
setIconSize(QSize(event->size().width() - 30, is.height()));
|
||||
setIconSize(QSize(qMax(event->size().width() - 40, MIN_LINE_LENGTH),
|
||||
is.height()));
|
||||
is = iconSize();
|
||||
|
||||
for (int i = 0; i < count(); i++) {
|
||||
@ -50,7 +55,8 @@ void StyleComboBox::resizeEvent(QResizeEvent *event)
|
||||
pm.fill(Qt::transparent);
|
||||
|
||||
QBrush brush(Qt::black);
|
||||
QPen pen(brush, is.height() / 7, (Qt::PenStyle) itemData(i).toInt());
|
||||
QPen pen(brush, is.height() / LINE_WIDTH_RATIO,
|
||||
(Qt::PenStyle) itemData(i).toInt());
|
||||
|
||||
QPainter painter(&pm);
|
||||
painter.setPen(pen);
|
||||
|
Loading…
x
Reference in New Issue
Block a user