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
@ -36,14 +36,14 @@ void ColorBox::paintEvent(QPaintEvent *event)
|
|||||||
painter.setBrush(_color);
|
painter.setBrush(_color);
|
||||||
painter.drawPrimitive(QStyle::PE_Frame, option);
|
painter.drawPrimitive(QStyle::PE_Frame, option);
|
||||||
#else // Q_OS_MAC || Q_OS_WIN32
|
#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.setBrush(_color);
|
||||||
painter.drawRect(event->rect().adjusted(-1, -1, 0, 0));
|
painter.setPen(Qt::NoPen);
|
||||||
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
|
painter.drawRect(event->rect().adjusted(2, 2, -2, -2));
|
||||||
#else // QT 5
|
// If works (QT5 and most QT4 styles) overpaints the previous rectangle
|
||||||
option.palette.setBrush(QPalette::Base, _color);
|
option.palette.setBrush(QPalette::Base, _color);
|
||||||
|
painter.drawPrimitive(QStyle::PE_PanelLineEdit, option);
|
||||||
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
|
painter.drawPrimitive(QStyle::PE_FrameLineEdit, option);
|
||||||
#endif // QT 5
|
|
||||||
#endif // Q_OS_MAC || Q_OS_WIN32
|
#endif // Q_OS_MAC || Q_OS_WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,10 @@
|
|||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include "stylecombobox.h"
|
#include "stylecombobox.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MIN_LINE_LENGTH 50
|
||||||
|
#define LINE_WIDTH_RATIO 7
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
||||||
|
|
||||||
StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
||||||
@ -11,7 +15,7 @@ StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
|||||||
Qt::DashDotLine, Qt::DashDotDotLine};
|
Qt::DashDotLine, Qt::DashDotDotLine};
|
||||||
|
|
||||||
QSize is = iconSize();
|
QSize is = iconSize();
|
||||||
setIconSize(QSize(sizeHint().width(), is.height()));
|
setIconSize(QSize(MIN_LINE_LENGTH, is.height()));
|
||||||
is = iconSize();
|
is = iconSize();
|
||||||
|
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(styles); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(styles); i++) {
|
||||||
@ -19,7 +23,7 @@ StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
|||||||
pm.fill(Qt::transparent);
|
pm.fill(Qt::transparent);
|
||||||
|
|
||||||
QBrush brush(Qt::black);
|
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);
|
QPainter painter(&pm);
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
@ -42,7 +46,8 @@ void StyleComboBox::setValue(Qt::PenStyle value)
|
|||||||
void StyleComboBox::resizeEvent(QResizeEvent *event)
|
void StyleComboBox::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
QSize is = iconSize();
|
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();
|
is = iconSize();
|
||||||
|
|
||||||
for (int i = 0; i < count(); i++) {
|
for (int i = 0; i < count(); i++) {
|
||||||
@ -50,7 +55,8 @@ void StyleComboBox::resizeEvent(QResizeEvent *event)
|
|||||||
pm.fill(Qt::transparent);
|
pm.fill(Qt::transparent);
|
||||||
|
|
||||||
QBrush brush(Qt::black);
|
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);
|
QPainter painter(&pm);
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user