From 9343fc6c77da8678df98ceb6330c61f43aa48737 Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 5 Mar 2017 05:51:22 +0100 Subject: Implement expand and collapse for DB view Sounds easy, right? It is, if you don't try to create a QIcon from a QChar. That took me a while... First, it's not a good idea to fill the QPixmap for the QIcon with transparency. That gives you a random background. Fill it with palette color instead. Then there's QFont's pixelSize(). I have absolutely no idea how it corresponds to the pixmap's size, but roughly double the width of the pixmap is a good guess... --- helper.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 helper.cpp (limited to 'helper.cpp') diff --git a/helper.cpp b/helper.cpp new file mode 100644 index 0000000..91e4d7f --- /dev/null +++ b/helper.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include "helper.h" + +namespace Helper { + QIcon iconFromQChar(const QChar &c, int pixelSize){ + QPixmap pm(QSize(64,64)); + QPainter p(&pm); + QFont f = p.font(); + f.setPixelSize(pixelSize); + p.setFont(f); + p.fillRect(pm.rect(), qApp->palette().color(QPalette::Window)); + p.setBrush(QBrush(Qt::black)); + p.drawText(pm.rect(), Qt::AlignCenter, c); + return QIcon(pm); + } + + QAction* createSeparator(QObject *parent){ + QAction *a = new QAction(parent); + a->setSeparator(true); + return a; + } +} -- cgit v1.2.3-70-g09d2