<html style="direction: ltr;">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <font face="Tahoma">Hi guys,<br>
      <br>
      I wrote a tiny class for delaying splash screen in C++ but when I
      tired to re-write it in python it didn't work!<br>
      <br>
      I got "AttributeError TeSplashScreen object has no attribut
      QFrate" although TeSplashScreen inherited from QFrame<br>
      <br>
      Could you please help me, I'm still a newbie in PyQt and Python.</font><br>
    <br>
    tesplashscreen.py<br>
    <pre><pre>from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
<font class="pastecode" color="#FF0000">class</font> TeSplashScreen(QFrame):
    <font class="pastecode" color="#008B00">""</font>"
    Splash doc
    <font class="pastecode" color="#008B00">""</font>"
       
    app = QApplication(sys.argv)
    sPixmap = QPixmap(10,  10)
    sMessage = QString()
    messages = [<font class="pastecode" color="#008B00">"nothing"</font>]
    sAlignment = 0
    sColor = QColor()
    
    def __init__(self,  pixmap):
        self.sPixmap =  pixmap
        self.QFrame(self, Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setFixedSize(sPixmap.size())
    
    def clearMessage(self):
        sMessage.clear()
        repaint()
    
    def showMessage(self,  theMessage, theAlignment, theColor):
        self.sMessage  = theMessage
        self.sAlignment = theAlignment
        self.sColor  = theColor
        repaint()
    
    def paintEvent(self, pe):
        aTextRect(rect())
        aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10)
        aPainter = QPainter(self)
        aPainter.drawPixmap(rect(), self.sPixmap)
        aPainter.setPen(self.sColor)
        aPainter.drawText(aTextRect, self.sAlignment, self.sMessage)
    
    def showSplash(self,  delay, messages, alignment, color):
        delay = 0
        self.messages = messages
        alignment = 0
        color = QColor(color)
        <font class="pastecode" color="#FF0000">class</font> SleeperThread(QThread):
            msecs = 0
            QThread.msleep(msecs)
        aSplashScreen = TeSplashScreen(self.sPixmap)
        aSplashScreen.show
        <font class="pastecode" color="#FF0000">for</font> i in range(len(messages)):
            aSplashScreen.showMessage(messages[i], alignment, color)
            SleeperThread.msleep(delay)
            
#    def showSplash(delay, messages, alignment, color):
#        delay = 0
#        messages = QStringList()
#        alignment = 0
#        color = QColor()
#        <font class="pastecode" color="#FF0000">class</font> SleeperThread(QThread):
#            msecs = 0
#            QThread.msleep(msecs)
#        aSplashScreen = TeSplashScreen(sPixmap)
#        aSplashScreen.show()
#        <font class="pastecode" color="#FF0000">for</font> i in range(messages.count()):
#            aSplashScreen.showMessage(messages[i], alignment, color)
#            SleeperThread.msleep(delay)
</pre></pre>
    <br>
    tesplashscreen.h<br>
    <pre><pre><font class="pastecode" color="#0000CD">#ifndef</font> TSPLASHSCREEN_H
<font class="pastecode" color="#0000CD">#define</font> TSPLASHSCREEN_H
<font class="pastecode" color="#0000CD">
#include</font> <QFrame>
<font class="pastecode" color="#0000CD">#include</font> <QPainter>
<font class="pastecode" color="#0000CD">#include</font> <QThread>

<font class="pastecode" color="#FF0000">class</font> TeSplashScreen : <font class="pastecode" color="#FF0000">public</font> QFrame
{
<font class="pastecode" color="#FF0000">public</font>:
    TeSplashScreen(<font class="pastecode" color="#FF0000">const</font> QPixmap& pixmap);
    <font class="pastecode" color="#4682B4">void</font> showMessage(<font class="pastecode" color="#FF0000">const</font> QString& theMessage, <font class="pastecode" color="#4682B4">int</font> theAlignment = <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">AlignLeft</font>, <font class="pastecode" color="#FF0000">const</font> QColor& theColor = <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">black</font>);
    <font class="pastecode" color="#4682B4">void</font> showSplash(<font class="pastecode" color="#4682B4">int</font> delay, QStringList messages, <font class="pastecode" color="#4682B4">int</font> alignment = <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">AlignLeft</font>, <font class="pastecode" color="#FF0000">const</font> QColor& color = <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">black</font>);
    <font class="pastecode" color="#4682B4">void</font> showSplash(QList<<font class="pastecode" color="#4682B4">int</font>> delaies, <font class="pastecode" color="#4682B4">int</font> defaultDelay, QStringList messages, <font class="pastecode" color="#4682B4">int</font> alignment = <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">AlignLeft</font>, <font class="pastecode" color="#FF0000">const</font> QColor& color = <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">black</font>);

<font class="pastecode" color="#FF0000">private</font>:
    <font class="pastecode" color="#FF0000">virtual</font> <font class="pastecode" color="#4682B4">void</font> paintEvent(QPaintEvent* pe);
    <font class="pastecode" color="#4682B4">void</font> clearMessage();
    QPixmap sPixmap;
    QString sMessage;
    <font class="pastecode" color="#4682B4">int</font> sAlignment;
    QColor sColor;
};
<font class="pastecode" color="#0000CD">
#endif</font> <font class="pastecode" color="#0000FF">// TSPLASHSCREEN_H</font>
</pre></pre>
    <br>
    tesplashscreen.cpp<br>
    <pre><pre><font class="pastecode" color="#0000CD">#include</font> <font class="pastecode" color="#008B00">"tesplashscreen.h"</font>

<font class="pastecode" color="#8B0000">TeSplashScreen::</font><font color="#FF0000">TeSplashScreen</font>(<font class="pastecode" color="#FF0000">const</font> QPixmap& thePixmap)
    : QFrame(0, <font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">FramelessWindowHint</font>|<font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">WindowStaysOnTopHint</font>)
    , sPixmap(thePixmap)
{
    setAttribute(<font class="pastecode" color="#8B0000">Qt::</font><font color="#FF0000">WA_TranslucentBackground</font>);
    setFixedSize(sPixmap.size());
};

<font class="pastecode" color="#4682B4">void</font> <font class="pastecode" color="#8B0000">TeSplashScreen::</font><font color="#FF0000">clearMessage</font>()
{
    sMessage.clear();
    repaint();
}

<font class="pastecode" color="#4682B4">void</font> <font class="pastecode" color="#8B0000">TeSplashScreen::</font><font color="#FF0000">showMessage</font>(<font class="pastecode" color="#FF0000">const</font> QString& theMessage, <font class="pastecode" color="#4682B4">int</font> theAlignment, <font class="pastecode" color="#FF0000">const</font> QColor& theColor)
{
    sMessage  = theMessage;
    sAlignment = theAlignment;
    sColor  = theColor;
    repaint();
}

<font class="pastecode" color="#4682B4">void</font> <font class="pastecode" color="#8B0000">TeSplashScreen::</font><font color="#FF0000">paintEvent</font>(QPaintEvent* pe)
{
    QRect aTextRect(rect());
    aTextRect.setRect(aTextRect.x()+5, aTextRect.y()+5, aTextRect.width()-10, aTextRect.height()-10);

    QPainter aPainter(<font class="pastecode" color="#FF0000">this</font>);
    aPainter.drawPixmap(rect(), sPixmap);
    aPainter.setPen(sColor);
    aPainter.drawText(aTextRect, sAlignment, sMessage);
}

<font class="pastecode" color="#4682B4">void</font> <font class="pastecode" color="#8B0000">TeSplashScreen::</font><font color="#FF0000">showSplash</font>(<font class="pastecode" color="#4682B4">int</font> delay, QStringList messages, <font class="pastecode" color="#4682B4">int</font> alignment, <font class="pastecode" color="#FF0000">const</font> QColor& color)
{
    <font class="pastecode" color="#FF0000">class</font> SleeperThread : <font class="pastecode" color="#FF0000">public</font> QThread
    {
    <font class="pastecode" color="#FF0000">public</font>:
        <font class="pastecode" color="#FF0000">static</font> <font class="pastecode" color="#4682B4">void</font> msleep(<font class="pastecode" color="#4682B4">unsigned</font> <font class="pastecode" color="#4682B4">long</font> msecs) {<font class="pastecode" color="#8B0000">QThread::</font><font color="#FF0000">msleep</font>(msecs);}
    };

    TeSplashScreen* aSplashScreen = <font class="pastecode" color="#FF0000">new</font> TeSplashScreen(sPixmap);
    aSplashScreen->show();

    <font class="pastecode" color="#FF0000">for</font>(<font class="pastecode" color="#4682B4">int</font> i=0; i<messages.count();++i)
    {
        aSplashScreen->showMessage(messages[i], alignment, color);
        <font class="pastecode" color="#8B0000">SleeperThread::</font><font color="#FF0000">msleep</font>(delay);
    }

    <font class="pastecode" color="#FF0000">delete</font> aSplashScreen;
}

<font class="pastecode" color="#4682B4">void</font> <font class="pastecode" color="#8B0000">TeSplashScreen::</font><font color="#FF0000">showSplash</font>(QList<<font class="pastecode" color="#4682B4">int</font>> delaies, <font class="pastecode" color="#4682B4">int</font> defaultDelay, QStringList messages, <font class="pastecode" color="#4682B4">int</font> alignment, <font class="pastecode" color="#FF0000">const</font> QColor& color)
{
    <font class="pastecode" color="#FF0000">class</font> SleeperThread : <font class="pastecode" color="#FF0000">public</font> QThread
    {
    <font class="pastecode" color="#FF0000">public</font>:
        <font class="pastecode" color="#FF0000">static</font> <font class="pastecode" color="#4682B4">void</font> msleep(<font class="pastecode" color="#4682B4">unsigned</font> <font class="pastecode" color="#4682B4">long</font> msecs) {<font class="pastecode" color="#8B0000">QThread::</font><font color="#FF0000">msleep</font>(msecs);}
    };

    TeSplashScreen* aSplashScreen = <font class="pastecode" color="#FF0000">new</font> TeSplashScreen(sPixmap);
    aSplashScreen->show();

    <font class="pastecode" color="#FF0000">for</font>(<font class="pastecode" color="#4682B4">int</font> i=0; i<messages.count();++i)
    {
        aSplashScreen->showMessage(messages[i], alignment, color);
        <font class="pastecode" color="#FF0000">if</font>(i<delaies.count())
            <font class="pastecode" color="#8B0000">SleeperThread::</font><font color="#FF0000">msleep</font>(delaies[i]);
        <font class="pastecode" color="#FF0000">else</font>
            <font class="pastecode" color="#8B0000">SleeperThread::</font><font color="#FF0000">msleep</font>(defaultDelay);
    }

    <font class="pastecode" color="#FF0000">delete</font> aSplashScreen;
}
</pre></pre>
    <br>
    <pre class="moz-signature" cols="72">-- 
Best Regards
Muhammad Bashir Al-Noimi
My Blog: <a class="moz-txt-link-freetext" href="http://mbnoimi.net">http://mbnoimi.net</a></pre>
  </body>
</html>