Results 1 to 13 of 13

Thread: Reimplement QSplashScreen::drawContents

  1. #1
    ucomesdag Guest

    Default Reimplement QSplashScreen::drawContents

    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.

    Qt Code:
    1. #ifndef CUSTOMSPLASHSCREEN_H
    2. #define CUSTOMSPLASHSCREEN_H
    3.  
    4. #include <QSplashScreen>
    5. #include <QPainter>
    6.  
    7. class customSplashScreen
    8. :public QSplashScreen
    9. {
    10.  
    11. public:
    12. customSplashScreen(const QPixmap& pixmap);
    13. ~customSplashScreen();
    14. virtual void drawContents(QPainter *painter);
    15. virtual void mousePressEvent(QMouseEvent *);
    16. };
    17.  
    18. #endif // CUSTOMSPLASHSCREEN_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "customSplashScreen.h"
    2.  
    3. customSplashScreen::customSplashScreen(const QPixmap& pixmap)
    4. {
    5. QSplashScreen::setPixmap(pixmap);
    6. };
    7.  
    8. customSplashScreen::~customSplashScreen()
    9. {
    10. };
    11.  
    12. void customSplashScreen::drawContents(QPainter *painter)
    13. {
    14. QPixmap textPix = QSplashScreen::pixmap();
    15. painter->setPen(Qt::black);
    16. QRect r = rect();
    17. r.setRect( 170, 397, 245, 14 );
    18. painter->drawText(r, "Loading something message...");
    19. };
    20.  
    21. void customSplashScreen::mousePressEvent(QMouseEvent *)
    22. {
    23. this->hide();
    24. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplement QSplashScreen::drawContents

    QSplashScreen::drawContents() and QWidget::mousePressEvent() are protected functions, you can't redeclare them as public. In other words, they aren't overridden.
    J-P Nurmi

  3. #3
    ucomesdag Guest

    Default Re: Reimplement QSplashScreen::drawContents

    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....

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplement QSplashScreen::drawContents

    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.
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by jpn View Post
    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.

  6. The following 3 users say thank you to jacek for this useful post:

    jpn (23rd November 2006), sunil.thaha (24th November 2006)

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by ucomesdag View Post
    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?

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reimplement QSplashScreen::drawContents

    But the fact remains that ucomesdag tries to implement something which is already implemented.

  9. #8
    ucomesdag Guest

    Default Re: Reimplement QSplashScreen::drawContents

    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....

  10. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by jacek View Post
    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?
    J-P Nurmi

  11. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by ucomesdag View Post
    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.
    J-P Nurmi

  12. The following user says thank you to jpn for this useful post:


  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by jpn View Post
    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++.

  14. #12
    ucomesdag Guest

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by jpn View Post
    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...

  15. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reimplement QSplashScreen::drawContents

    Quote Originally Posted by jpn View Post
    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:

    Qt Code:
    1. class A {
    2. protected:
    3. virtual int foo(); // virtual so can be overrriden
    4. };
    5.  
    6. class B : public A {
    7. private:
    8. int foo(); // overrides A::foo and changes visibility to private
    9. };
    10.  
    11. class C : public B {
    12. //... doesn't have any redeclaration of foo() so if
    13. // one looks at this class definition one doesn't realise
    14. // there is a foo() method defined
    15. };
    16.  
    17. class D : public C {
    18. public:
    19. int foo(); // ???
    20. };
    To copy to clipboard, switch view to plain text mode 

    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.