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
Qt Code:
  1. const int steps = 10;
  2. const double stride = 0.5 / steps;
  3.  
  4. class faderIn : public QThread
  5. {
  6. public:
  7. faderIn(MainWindow* instance)
  8. {
  9. m_instance = instance;
  10. }
  11. virtual void run()
  12. {
  13. while( m_instance->windowOpacity() < 1 )
  14. {
  15. msleep( 10 );
  16. m_instance->setWindowOpacity(m_instance->windowOpacity() + stride);
  17. }
  18. m_instance->setWindowOpacity(1);
  19. }
  20.  
  21. private:
  22. MainWindow* m_instance;
  23. };
  24. class faderOut : public QThread
  25. {
  26. public:
  27. faderOut(MainWindow* instance)
  28. {
  29. m_instance = instance;
  30. }
  31. virtual void run()
  32. {
  33. while( m_instance->windowOpacity() > 0.5) {
  34. msleep( 10 );
  35.  
  36. m_instance->setWindowOpacity(m_instance->windowOpacity() - stride);
  37. }
  38. m_instance->setWindowOpacity(0.5);
  39. }
  40.  
  41. private:
  42. MainWindow* m_instance;
  43. };
  44. class newMain : public MainWindow
  45. {
  46. protected:
  47. bool event( QEvent * e )
  48. {
  49. bool retVal = MainWindow::event(e);
  50. if (e->type() == QEvent::HoverEnter)
  51. {
  52. faderIn(this).run();
  53. }
  54. if (e->type() == QEvent::HoverLeave)
  55. {
  56. faderOut(this).run();
  57. }
  58. return retVal;
  59.  
  60. }
  61.  
  62.  
  63. };
  64. int main(int argc, char *argv[])
  65. {
  66. QApplication a(argc, argv);
  67. newMain w;
  68.  
  69. w.show();
  70. return a.exec();
  71. }
To copy to clipboard, switch view to plain text mode