PDA

View Full Version : Problem with a dialog transparency



ManicQin
27th May 2009, 09:11
Hi all,
I tried to add a transparency effect when the user HoverLeave or HoverEnter the dialog.
It works great the problem is that when leaving the dialog I have this wierd black dialog for a minute...
I added the exact code I'm using I'll be happy if you could comment out the problem


const int steps = 10;
const double stride = 0.5 / steps;

class faderIn : public QThread
{
public:
faderIn(MainWindow* instance)
{
m_instance = instance;
}
virtual void run()
{
while( m_instance->windowOpacity() < 1 )
{
msleep( 10 );
m_instance->setWindowOpacity(m_instance->windowOpacity() + stride);
}
m_instance->setWindowOpacity(1);
}

private:
MainWindow* m_instance;
};
class faderOut : public QThread
{
public:
faderOut(MainWindow* instance)
{
m_instance = instance;
}
virtual void run()
{
while( m_instance->windowOpacity() > 0.5) {
msleep( 10 );

m_instance->setWindowOpacity(m_instance->windowOpacity() - stride);
}
m_instance->setWindowOpacity(0.5);
}

private:
MainWindow* m_instance;
};
class newMain : public MainWindow
{
protected:
bool event( QEvent * e )
{
bool retVal = MainWindow::event(e);
if (e->type() == QEvent::HoverEnter)
{
faderIn(this).run();
}
if (e->type() == QEvent::HoverLeave)
{
faderOut(this).run();
}
return retVal;

}


};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
newMain w;

w.show();
return a.exec();
}