Results 1 to 3 of 3

Thread: Problem: QDialog change background when move the mouse

  1. #1
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Problem: QDialog change background when move the mouse

    I implemented a QDialog with transparent background, but i move the mouse over QDialog, background becomes dark.

    What's the problem?


    my code:

    Note: numPadDialog is derived class of QDialog.

    Qt Code:
    1. // Constructor, call some functions to implent QDialog
    2. numPadDialog::numPadDialog() {
    3. // TODO Auto-generated constructor stub
    4. setWallpaper(); //This function try put a background dark semi-transparent
    5. setNumericPad(); // This function put the image of numpad
    6. configureInterfaceNumericPad(); // This function configure map of the buttons of numpad
    7. setInfo("Configure this parameter: "); //This function put extra information about numPad
    8. showDialog(); // This function show the QDialog
    9. }
    10.  
    11. //This function try put a background dark semi-transparent
    12. void numPadDialog::setWallpaper(){
    13.  
    14. mask= new QLabel(this);
    15. //set image
    16. QString style;
    17. style.clear();
    18. QString numPadPath;
    19. numPadPath.clear();
    20. numPadPath.append(QDir::currentPath());
    21. numPadPath.append(WALLPAPER_DIRECTORY);
    22. numPadPath.append(KEYPAD_BACKGROUND); // image semi-transparent, dark
    23.  
    24. style.append("background-color: transparent; background: transparent; background-image: url(");
    25. style.append(numPadPath);
    26. style.append("); ");
    27. mask->setStyleSheet(style);
    28. mask->setGeometry(0,0,320,240);
    29. mask->setFocusPolicy(Qt::NoFocus);
    30. }
    31.  
    32.  
    33. // This function put the image of numpad
    34. void numPadDialog::setNumericPad(){
    35.  
    36. numPad= new QLabel(this);
    37. //set image
    38. QString style;
    39. style.clear();
    40. QString numPadPath;
    41. numPadPath.clear();
    42. numPadPath.append(QDir::currentPath());
    43. numPadPath.append(WALLPAPER_DIRECTORY);
    44. numPadPath.append(KEYPAD_NUMPAD);
    45.  
    46. style.append("background-color: transparent; background: transparent; background-image: url(");
    47. style.append(numPadPath);
    48. style.append("); ");
    49. numPad->setStyleSheet(style);
    50. numPad->setGeometry(0,0,320,240);
    51. numPad->setFocusPolicy(Qt::NoFocus);
    52. }
    53.  
    54. // This function show the QDialog
    55. void numPadDialog::showDialog(){
    56. this->setWindowFlags(Qt::FramelessWindowHint);
    57. this->setAttribute(Qt::WA_NoSystemBackground);
    58. //this->setAttribute(Qt::WA_TransparentForMouseEvents);
    59. //this->setAttribute(Qt::WA_NoBackground);
    60. this->setFixedSize(320,240); // ( x , y )
    61. this->setFocusPolicy(Qt::NoFocus);
    62. exec();
    63. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Problem: QDialog change background when move the mouse

    Don't use stylesheets. Either use QPalette or just paint the background in the paint event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2011
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem: QDialog change background when move the mouse

    Thank's for your help wysota! but don't works

    i need to charge 2 images:

    first-> semi-transparent background
    second-> image of keypad

    I have to try with QPalette but screen is black.

    the code used is:


    Qt Code:
    1. //set background
    2. QString wallPaperPath;
    3. wallPaperPath.clear();
    4. wallPaperPath.append(QDir::currentPath());
    5. wallPaperPath.append(WALLPAPER_DIRECTORY);
    6. wallPaperPath.append(KEYPAD_NUMPAD); //this line charge the keypad image but first i use the background image------> wallPaperPath.append(BACKGROUND); in other previus function
    7. //wallPaperPath.append(WALLPAPER);
    8.  
    9. QImage image;
    10. image.load(wallPaperPath,0);
    11. QBrush brush;
    12. brush.setStyle(Qt::SolidPattern);
    13. brush.setTextureImage(image);
    14.  
    15. QPalette palette;
    16. palette.setBrush(QPalette::Active, QPalette::Window, brush);
    17. palette.setBrush(QPalette::Inactive, QPalette::Window, brush);
    18. palette.setBrush(QPalette::Disabled, QPalette::Window, brush);
    19. palette.setBrush(QPalette::Normal, QPalette::Window, brush);
    20. palette.setBrush(QPalette::Current, QPalette::Window, brush);
    21.  
    22. palette.setBrush(QPalette::Active, QPalette::Background, brush);
    23. palette.setBrush(QPalette::Inactive, QPalette::Background, brush);
    24. palette.setBrush(QPalette::Disabled, QPalette::Background, brush);
    25. palette.setBrush(QPalette::Normal, QPalette::Background, brush);
    26. palette.setBrush(QPalette::Current, QPalette::Background, brush);
    27.  
    28. palette.setBrush(QPalette::Active, QPalette::Foreground, brush);
    29. palette.setBrush(QPalette::Inactive, QPalette::Foreground, brush);
    30. palette.setBrush(QPalette::Disabled, QPalette::Foreground, brush);
    31. palette.setBrush(QPalette::Normal, QPalette::Foreground, brush);
    32. palette.setBrush(QPalette::Current, QPalette::Foreground, brush);
    33.  
    34. palette.setBrush(QPalette::Active, QPalette::Base, brush);
    35. palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
    36. palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
    37. palette.setBrush(QPalette::Normal, QPalette::Base, brush);
    38. palette.setBrush(QPalette::Current, QPalette::Base, brush);
    39.  
    40. palette.setBrush(QPalette::Active, QPalette::AlternateBase, brush);
    41. palette.setBrush(QPalette::Inactive, QPalette::AlternateBase, brush);
    42. palette.setBrush(QPalette::Disabled, QPalette::AlternateBase, brush);
    43. palette.setBrush(QPalette::Normal, QPalette::AlternateBase, brush);
    44. palette.setBrush(QPalette::Current, QPalette::AlternateBase, brush);
    45.  
    46. palette.setBrush(QPalette::Active, QPalette::Highlight, brush);
    47. palette.setBrush(QPalette::Inactive, QPalette::Highlight, brush);
    48. palette.setBrush(QPalette::Disabled, QPalette::Highlight, brush);
    49. palette.setBrush(QPalette::Normal, QPalette::Highlight, brush);
    50. palette.setBrush(QPalette::Current, QPalette::Highlight, brush);
    51.  
    52. palette.setBrush(QPalette::Active, QPalette::Light, brush);
    53. palette.setBrush(QPalette::Inactive, QPalette::Light, brush);
    54. palette.setBrush(QPalette::Disabled, QPalette::Light, brush);
    55. palette.setBrush(QPalette::Normal, QPalette::Light, brush);
    56. palette.setBrush(QPalette::Current, QPalette::Light, brush);
    57.  
    58. this->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 3rd August 2011, 01:14
  2. Replies: 0
    Last Post: 28th June 2011, 07:41
  3. Replies: 5
    Last Post: 7th December 2010, 21:02
  4. Replies: 0
    Last Post: 7th October 2010, 15:52
  5. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34

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.