PDA

View Full Version : Reimplement QSplashScreen::drawContents



ucomesdag
23rd November 2006, 19:56
I'm looking for a way to get the currAlign and the currStatus

//painter->drawText(r, d_func()->currAlign, d_func()->currStatus);

and also to make the hide on mousePressEvent work.


#ifndef CUSTOMSPLASHSCREEN_H
#define CUSTOMSPLASHSCREEN_H

#include <QSplashScreen>
#include <QPainter>

class customSplashScreen
:public QSplashScreen
{

public:
customSplashScreen(const QPixmap& pixmap);
~customSplashScreen();
virtual void drawContents(QPainter *painter);
virtual void mousePressEvent(QMouseEvent *);
};

#endif // CUSTOMSPLASHSCREEN_H

#include "customSplashScreen.h"

customSplashScreen::customSplashScreen(const QPixmap& pixmap)
{
QSplashScreen::setPixmap(pixmap);
};

customSplashScreen::~customSplashScreen()
{
};

void customSplashScreen::drawContents(QPainter *painter)
{
QPixmap textPix = QSplashScreen::pixmap();
painter->setPen(Qt::black);
QRect r = rect();
r.setRect( 170, 397, 245, 14 );
painter->drawText(r, "Loading something message...");
};

void customSplashScreen::mousePressEvent(QMouseEvent *)
{
this->hide();
};

jpn
23rd November 2006, 20:05
QSplashScreen::drawContents() and QWidget::mousePressEvent() are protected functions, you can't redeclare them as public. In other words, they aren't overridden.

ucomesdag
23rd November 2006, 20:23
void QSplashScreen::drawContents ( QPainter * painter ) [virtual protected]
Draw the contents of the splash screen using painter painter. The default implementation draws the message passed by showMessage(). Reimplement this function if you want to do your own drawing on the splash screen.

Btw. It works only I don't know how to get the alignment and message from the parent class.
For the mousePressEvent I know I'm wondering if there is a way....

jpn
23rd November 2006, 20:50
But are you planning to do something more complex than showing a pixmap and a message? QSplashScreen already has built-in support for both.



I'm looking for a way to get the currAlign and the currStatus

//painter->drawText(r, d_func()->currAlign, d_func()->currStatus);

These are part of QSplashScreen private implementation and there is basically no way for you to access them. QSplashScreen already draws the pixmap and the message for you. As I have understood, QSplashScreen::drawContents() is provided just for the possibility to add more custom decoration or such.


and also to make the hide on mousePressEvent work.
Seems like QSplashScreen declares mousePressEvent() as non-virtual so it cannot be overridden. The QSplashScreen::mousePressEvent() implementation already hides the splashscreen.

jacek
23rd November 2006, 20:57
Seems like QSplashScreen declares mousePressEvent() as non-virtual so it cannot be overridden. The QSplashScreen::mousePressEvent() implementation already hides the splashscreen.
Once a method was declared as virtual, it will be virtual in all subclasses, regardless if one uses the "virtual" keyword or not.

jacek
23rd November 2006, 21:03
void customSplashScreen::mousePressEvent(QMouseEvent *)
{
this->hide();
};
Do you plan to have something more complex here? Because this doesn't differ from QSplashScreen::mousePressEvent().

Maybe it doesn't "work" because you block the event loop in some other part of your application?

wysota
23rd November 2006, 21:06
But the fact remains that ucomesdag tries to implement something which is already implemented.

ucomesdag
23rd November 2006, 21:20
Well if you looked you well you see that I set the position of where the text appears from show message....

r.setRect( 170, 397, 245, 14 );
painter->drawText(r, "Loading something message...");

It all works only I'm looking for a way to get the "d_func()->currAlign" and "d_func()->currStatus" from QSplashScreen.

For the mouse press thing I see I'm wrong....

jpn
23rd November 2006, 21:20
Once a method was declared as virtual, it will be virtual in all subclasses, regardless if one uses the "virtual" keyword or not.
Thanks for pointing this out. I wonder where did I get the faulty idea from.

And grr, same thing with the declaration story. I some why thought that a private or protected method couldn't be declared as public in a subclass. Neither gcc 4 or msvc 2005 prevents that. Could it be possible that it's prevented in either older version of gcc or msvc?

jpn
23rd November 2006, 21:44
It all works only I'm looking for a way to get the "d_func()->currAlign" and "d_func()->currStatus" from QSplashScreen.

It's all wrapped inside QSplashScreenPrivate which you unfortunately cannot access. All you can do is to implement your own similar version of showMessage() and store the alignment as a member variable in the subclass.

jacek
23rd November 2006, 21:46
Neither gcc 4 or msvc 2005 prevents that. Could it be possible that it's prevented in either older version of gcc or msvc?
AFAIR, long ago there were some rules that said how can one change method and field visibility, but it could be in a pre-standard C++.

ucomesdag
23rd November 2006, 21:55
It's all wrapped inside QSplashScreenPrivate which you unfortunately cannot access. All you can do is to implement your own similar version of showMessage() and store the alignment as a member variable in the subclass.

Will do that... thanks a lot...

wysota
24th November 2006, 09:39
And grr, same thing with the declaration story. I some why thought that a private or protected method couldn't be declared as public in a subclass. Neither gcc 4 or msvc 2005 prevents that. Could it be possible that it's prevented in either older version of gcc or msvc?

I think we could have a separate discussion on that, but I also thought that you can't redeclare a private/protected method as public - that you can only reduce the visibility, not increase it. For instance:


class A {
protected:
virtual int foo(); // virtual so can be overrriden
};

class B : public A {
private:
int foo(); // overrides A::foo and changes visibility to private
};

class C : public B {
//... doesn't have any redeclaration of foo() so if
// one looks at this class definition one doesn't realise
// there is a foo() method defined
};

class D : public C {
public:
int foo(); // ???
};

Will D::foo() override B::foo()? I thought you can declare a public method with the same signature as a private method of a superclass, but the two methods won't clash and that this is the whole idea of having private scopes. If one can gain access to a virtual private member by redeclaring it as public, then what sense does it make to have private members at all? Did you check that these will be related to the same virtual method or maybe simply the compiler creates two distinct methods from such a declaration?