PDA

View Full Version : Problem: QDialog change background when move the mouse



Gerard
4th October 2011, 18:35
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.





// Constructor, call some functions to implent QDialog
numPadDialog::numPadDialog() {
// TODO Auto-generated constructor stub
setWallpaper(); //This function try put a background dark semi-transparent
setNumericPad(); // This function put the image of numpad
configureInterfaceNumericPad(); // This function configure map of the buttons of numpad
setInfo("Configure this parameter: "); //This function put extra information about numPad
showDialog(); // This function show the QDialog
}

//This function try put a background dark semi-transparent
void numPadDialog::setWallpaper(){

mask= new QLabel(this);
//set image
QString style;
style.clear();
QString numPadPath;
numPadPath.clear();
numPadPath.append(QDir::currentPath());
numPadPath.append(WALLPAPER_DIRECTORY);
numPadPath.append(KEYPAD_BACKGROUND); // image semi-transparent, dark

style.append("background-color: transparent; background: transparent; background-image: url(");
style.append(numPadPath);
style.append("); ");
mask->setStyleSheet(style);
mask->setGeometry(0,0,320,240);
mask->setFocusPolicy(Qt::NoFocus);
}


// This function put the image of numpad
void numPadDialog::setNumericPad(){

numPad= new QLabel(this);
//set image
QString style;
style.clear();
QString numPadPath;
numPadPath.clear();
numPadPath.append(QDir::currentPath());
numPadPath.append(WALLPAPER_DIRECTORY);
numPadPath.append(KEYPAD_NUMPAD);

style.append("background-color: transparent; background: transparent; background-image: url(");
style.append(numPadPath);
style.append("); ");
numPad->setStyleSheet(style);
numPad->setGeometry(0,0,320,240);
numPad->setFocusPolicy(Qt::NoFocus);
}

// This function show the QDialog
void numPadDialog::showDialog(){
this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_NoSystemBackground);
//this->setAttribute(Qt::WA_TransparentForMouseEvents);
//this->setAttribute(Qt::WA_NoBackground);
this->setFixedSize(320,240); // ( x , y )
this->setFocusPolicy(Qt::NoFocus);
exec();
}

wysota
7th October 2011, 23:46
Don't use stylesheets. Either use QPalette or just paint the background in the paint event.

Gerard
21st October 2011, 11:25
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:





//set background
QString wallPaperPath;
wallPaperPath.clear();
wallPaperPath.append(QDir::currentPath());
wallPaperPath.append(WALLPAPER_DIRECTORY);
wallPaperPath.append(KEYPAD_NUMPAD); //this line charge the keypad image but first i use the background image------> wallPaperPath.append(BACKGROUND); in other previus function
//wallPaperPath.append(WALLPAPER);

QImage image;
image.load(wallPaperPath,0);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setTextureImage(image);

QPalette palette;
palette.setBrush(QPalette::Active, QPalette::Window, brush);
palette.setBrush(QPalette::Inactive, QPalette::Window, brush);
palette.setBrush(QPalette::Disabled, QPalette::Window, brush);
palette.setBrush(QPalette::Normal, QPalette::Window, brush);
palette.setBrush(QPalette::Current, QPalette::Window, brush);

palette.setBrush(QPalette::Active, QPalette::Background, brush);
palette.setBrush(QPalette::Inactive, QPalette::Background, brush);
palette.setBrush(QPalette::Disabled, QPalette::Background, brush);
palette.setBrush(QPalette::Normal, QPalette::Background, brush);
palette.setBrush(QPalette::Current, QPalette::Background, brush);

palette.setBrush(QPalette::Active, QPalette::Foreground, brush);
palette.setBrush(QPalette::Inactive, QPalette::Foreground, brush);
palette.setBrush(QPalette::Disabled, QPalette::Foreground, brush);
palette.setBrush(QPalette::Normal, QPalette::Foreground, brush);
palette.setBrush(QPalette::Current, QPalette::Foreground, brush);

palette.setBrush(QPalette::Active, QPalette::Base, brush);
palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
palette.setBrush(QPalette::Disabled, QPalette::Base, brush);
palette.setBrush(QPalette::Normal, QPalette::Base, brush);
palette.setBrush(QPalette::Current, QPalette::Base, brush);

palette.setBrush(QPalette::Active, QPalette::AlternateBase, brush);
palette.setBrush(QPalette::Inactive, QPalette::AlternateBase, brush);
palette.setBrush(QPalette::Disabled, QPalette::AlternateBase, brush);
palette.setBrush(QPalette::Normal, QPalette::AlternateBase, brush);
palette.setBrush(QPalette::Current, QPalette::AlternateBase, brush);

palette.setBrush(QPalette::Active, QPalette::Highlight, brush);
palette.setBrush(QPalette::Inactive, QPalette::Highlight, brush);
palette.setBrush(QPalette::Disabled, QPalette::Highlight, brush);
palette.setBrush(QPalette::Normal, QPalette::Highlight, brush);
palette.setBrush(QPalette::Current, QPalette::Highlight, brush);

palette.setBrush(QPalette::Active, QPalette::Light, brush);
palette.setBrush(QPalette::Inactive, QPalette::Light, brush);
palette.setBrush(QPalette::Disabled, QPalette::Light, brush);
palette.setBrush(QPalette::Normal, QPalette::Light, brush);
palette.setBrush(QPalette::Current, QPalette::Light, brush);

this->setPalette(palette);