I solved this by creating a dedicated widget and reimplementing paintEvent().
Incase anyone is seeking a similar solution (I did not find anything on Google relating to changing QGraphicsScene font colour), this is what I did:
splashscreen.h
#ifndef SPLASHSCREEN_H
#define SPLASHSCREEN_H
#include <QWidget>
#include <QPainter>
class SplashScreen
: public QWidget{
Q_OBJECT
public:
explicit SplashScreen
(QWidget *parent
= 0);
protected:
void paintEvent
(QPaintEvent *pEvent
);
// Reimplement paintEvent() to allow access to QPainter
private:
// UI Elements
};
#endif // SPLASHSCREEN_H
#ifndef SPLASHSCREEN_H
#define SPLASHSCREEN_H
#include <QWidget>
#include <QPainter>
class SplashScreen : public QWidget
{
Q_OBJECT
public:
explicit SplashScreen(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *pEvent); // Reimplement paintEvent() to allow access to QPainter
private:
// UI Elements
QPainter *painter;
};
#endif // SPLASHSCREEN_H
To copy to clipboard, switch view to plain text mode
splashscreen.cpp
#include "splashscreen.h"
{
// Nothing required here
}
// Reimplemented paintEvent()
{
painter
= new QPainter(this);
// Initialise painter
lGrad.setColorAt(0, Qt::black);
lGrad.setColorAt(1, Qt::darkBlue);
painter->fillRect(0, 0, 800, 440, lGrad);
painter->setPen(Qt::white); // Add text
painter->drawText(320, 150, "Media Library v0.1");
painter->drawText(20, 400, "Gavin Harper (F8827)");
}
#include "splashscreen.h"
SplashScreen::SplashScreen(QWidget *parent) : QWidget(parent)
{
// Nothing required here
}
// Reimplemented paintEvent()
void SplashScreen::paintEvent(QPaintEvent *pEvent)
{
painter = new QPainter(this); // Initialise painter
QLinearGradient lGrad(QPointF(500, 350), QPointF(700, 400)); // Set a gradient background
lGrad.setColorAt(0, Qt::black);
lGrad.setColorAt(1, Qt::darkBlue);
painter->fillRect(0, 0, 800, 440, lGrad);
painter->setPen(Qt::white); // Add text
painter->drawText(320, 150, "Media Library v0.1");
painter->drawText(20, 400, "Gavin Harper (F8827)");
}
To copy to clipboard, switch view to plain text mode
Bookmarks