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();
}
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();
}