Results 1 to 3 of 3

Thread: [PyQt] Delaying splash screen

  1. #1
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default [PyQt] Delaying splash screen

    Hi guys,

    I wrote a tiny class for delaying splash screen in C++ but when I tired to re-write in python it didn't work!

    Could you please help me, I'm still a newbie in PyQt.

    tesplashscreen.py
    Qt Code:
    1. from PyQt4.QtCore import *
    2. from PyQt4.QtGui import *
    3. import sys
    4. class TeSplashScreen(QFrame):
    5. """
    6. Splash doc
    7. """
    8.  
    9. app = QApplication(sys.argv)
    10. sPixmap = QPixmap(10, 10)
    11. sMessage = QString()
    12. messages = ["nothing"]
    13. sAlignment = 0
    14. sColor = QColor()
    15.  
    16. def __init__(self, pixmap):
    17. self.sPixmap = pixmap
    18. self.QFrame(self, Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
    19. self.setAttribute(Qt.WA_TranslucentBackground)
    20. self.setFixedSize(sPixmap.size())
    21.  
    22. def clearMessage(self):
    23. sMessage.clear()
    24. repaint()
    25.  
    26. def showMessage(self, theMessage, theAlignment, theColor):
    27. self.sMessage = theMessage
    28. self.sAlignment = theAlignment
    29. self.sColor = theColor
    30. repaint()
    31.  
    32. def paintEvent(self, pe):
    33. aTextRect(rect())
    34. aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10)
    35. aPainter = QPainter(self)
    36. aPainter.drawPixmap(rect(), self.sPixmap)
    37. aPainter.setPen(self.sColor)
    38. aPainter.drawText(aTextRect, self.sAlignment, self.sMessage)
    39.  
    40. def showSplash(self, delay, messages, alignment, color):
    41. delay = 0
    42. self.messages = messages
    43. alignment = 0
    44. color = QColor(color)
    45. class SleeperThread(QThread):
    46. msecs = 0
    47. QThread.msleep(msecs)
    48. aSplashScreen = TeSplashScreen(self.sPixmap)
    49. aSplashScreen.show
    50. for i in range(len(messages)):
    51. aSplashScreen.showMessage(messages[i], alignment, color)
    52. SleeperThread.msleep(delay)
    53.  
    54. # def showSplash(delay, messages, alignment, color):
    55. # delay = 0
    56. # messages = QStringList()
    57. # alignment = 0
    58. # color = QColor()
    59. # class SleeperThread(QThread):
    60. # msecs = 0
    61. # QThread.msleep(msecs)
    62. # aSplashScreen = TeSplashScreen(sPixmap)
    63. # aSplashScreen.show()
    64. # for i in range(messages.count()):
    65. # aSplashScreen.showMessage(messages[i], alignment, color)
    66. # SleeperThread.msleep(delay)
    To copy to clipboard, switch view to plain text mode 

    tesplashscreen.h
    Qt Code:
    1. #ifndef TSPLASHSCREEN_H
    2. #define TSPLASHSCREEN_H
    3.  
    4. #include <QFrame>
    5. #include <QPainter>
    6. #include <QThread>
    7.  
    8. class TeSplashScreen : public QFrame
    9. {
    10. public:
    11. TeSplashScreen(const QPixmap& pixmap);
    12. void showMessage(const QString& theMessage, int theAlignment = Qt::AlignLeft, const QColor& theColor = Qt::black);
    13. void showSplash(int delay, QStringList messages, int alignment = Qt::AlignLeft, const QColor& color = Qt::black);
    14. void showSplash(QList<int> delaies, int defaultDelay, QStringList messages, int alignment = Qt::AlignLeft, const QColor& color = Qt::black);
    15.  
    16. private:
    17. virtual void paintEvent(QPaintEvent* pe);
    18. void clearMessage();
    19. QPixmap sPixmap;
    20. QString sMessage;
    21. int sAlignment;
    22. QColor sColor;
    23. };
    24.  
    25. #endif // TSPLASHSCREEN_H
    To copy to clipboard, switch view to plain text mode 

    tesplashscreen.cpp
    Qt Code:
    1. #include "tesplashscreen.h"
    2.  
    3. TeSplashScreen::TeSplashScreen(const QPixmap& thePixmap)
    4. : QFrame(0, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint)
    5. , sPixmap(thePixmap)
    6. {
    7. setAttribute(Qt::WA_TranslucentBackground);
    8. setFixedSize(sPixmap.size());
    9. };
    10.  
    11. void TeSplashScreen::clearMessage()
    12. {
    13. sMessage.clear();
    14. repaint();
    15. }
    16.  
    17. void TeSplashScreen::showMessage(const QString& theMessage, int theAlignment, const QColor& theColor)
    18. {
    19. sMessage = theMessage;
    20. sAlignment = theAlignment;
    21. sColor = theColor;
    22. repaint();
    23. }
    24.  
    25. void TeSplashScreen::paintEvent(QPaintEvent* pe)
    26. {
    27. QRect aTextRect(rect());
    28. aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10);
    29.  
    30. QPainter aPainter(this);
    31. aPainter.drawPixmap(rect(), sPixmap);
    32. aPainter.setPen(sColor);
    33. aPainter.drawText(aTextRect, sAlignment, sMessage);
    34. }
    35.  
    36. void TeSplashScreen::showSplash(int delay, QStringList messages, int alignment, const QColor& color)
    37. {
    38. class SleeperThread : public QThread
    39. {
    40. public:
    41. static void msleep(unsigned long msecs) {QThread::msleep(msecs);}
    42. };
    43.  
    44. TeSplashScreen* aSplashScreen = new TeSplashScreen(sPixmap);
    45. aSplashScreen->show();
    46.  
    47. for(int i=0; i<messages.count();++i)
    48. {
    49. aSplashScreen->showMessage(messages[i], alignment, color);
    50. SleeperThread::msleep(delay);
    51. }
    52.  
    53. delete aSplashScreen;
    54. }
    55.  
    56. void TeSplashScreen::showSplash(QList<int> delaies, int defaultDelay, QStringList messages, int alignment, const QColor& color)
    57. {
    58. class SleeperThread : public QThread
    59. {
    60. public:
    61. static void msleep(unsigned long msecs) {QThread::msleep(msecs);}
    62. };
    63.  
    64. TeSplashScreen* aSplashScreen = new TeSplashScreen(sPixmap);
    65. aSplashScreen->show();
    66.  
    67. for(int i=0; i<messages.count();++i)
    68. {
    69. aSplashScreen->showMessage(messages[i], alignment, color);
    70. if(i<delaies.count())
    71. SleeperThread::msleep(delaies[i]);
    72. else
    73. SleeperThread::msleep(defaultDelay);
    74. }
    75.  
    76. delete aSplashScreen;
    77. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: [PyQt] Delaying splash screen

    I modified py class but I faced a new issue I think it's related to using list (I don't know how to use QStringList in PyQt):
    Qt Code:
    1. TypeError object of type int has no len()
    To copy to clipboard, switch view to plain text mode 

    tesplashscreen.py
    Qt Code:
    1. from PyQt4.QtCore import *
    2. from PyQt4.QtGui import *
    3. import sys
    4. class TeSplashScreen(QFrame):
    5. """
    6. Splash doc
    7. """
    8.  
    9. app = QApplication(sys.argv)
    10. sPixmap = QPixmap(10, 10)
    11. sMessage = QString()
    12. # messages = ["nothing"]
    13. sAlignment = 0
    14. sColor = QColor()
    15.  
    16. def __init__(self, pixmap):
    17. super(QFrame, self).__init__()
    18. self.sPixmap = pixmap
    19. self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
    20. self.setAttribute(Qt.WA_TranslucentBackground)
    21. self.setFixedSize(self.sPixmap.size())
    22.  
    23. def clearMessage(self):
    24. self.sMessage.clear()
    25. self.repaint()
    26.  
    27. def showMessage(self, theMessage, theAlignment, theColor):
    28. self.sMessage = theMessage
    29. self.sAlignment = theAlignment
    30. self.sColor = theColor
    31. self.repaint()
    32.  
    33. def paintEvent(self, pe):
    34. aTextRect = QRect(self.rect())
    35. aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10)
    36. aPainter = QPainter(self)
    37. aPainter.drawPixmap(self.rect(), self.sPixmap)
    38. aPainter.setPen(self.sColor)
    39. aPainter.drawText(aTextRect, self.sAlignment, self.sMessage)
    40.  
    41. def showSplash(self, delay, messages, alignment, color):
    42. delay = 0
    43. # self.messages = messages
    44. alignment = 0
    45. color = QColor(color)
    46. class SleeperThread(QThread):
    47. msecs = 0
    48. QThread.msleep(msecs)
    49. aSplashScreen = TeSplashScreen(self.sPixmap)
    50. aSplashScreen.show
    51. for i in range(len(messages)):
    52. aSplashScreen.showMessage(messages[i], alignment, color)
    53. SleeperThread.msleep(delay)
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2018
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: [PyQt] Delaying splash screen

    thanks for you

Similar Threads

  1. Problem with Splash Screen ?
    By vinod in forum Qt Programming
    Replies: 13
    Last Post: 11th April 2020, 17:15
  2. splash screen problem
    By wizarda in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2011, 02:05
  3. How to Keep Splash Screen and App on Same Display
    By ajb_advance in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 11:49
  4. Splash screen showing for two seconds
    By Koas in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2008, 19:40
  5. Splash Screen
    By Salazaar in forum Newbie
    Replies: 27
    Last Post: 4th June 2007, 17:31

Tags for this Thread

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.