事例如下:创建了QMenu菜单,设置透明度的效果:
设置前:
myMenu = new QMenu;
myMenu->setWindowOpacity(1);//调节菜单的透明度,范围是1到0,1(完全不透明)到0(完全透明),如果不进行设置,默认的是1,可以把1改成零点几看一下效果QAction* openAction = new QAction(QString::fromLocal8Bit("打开文件"),NULL);
connect(openAction,SIGNAL(triggered()),this,SIGNAL(signal_open_file())); myMenu->addAction(openAction);QAction* registerAction = new QAction(QString::fromLocal8Bit("注册文件"),NULL);
connect(registerAction,SIGNAL(triggered()),this,SIGNAL(signal_register())); myMenu->addAction(registerAction);QAction* closeAction = new QAction(QString::fromLocal8Bit("关闭文件"),NULL);
connect(closeAction,SIGNAL(triggered()),this,SIGNAL(signal_close())); myMenu->addAction(closeAction); myMenu->setStyleSheet("QMenu {background-color: gray ;border: 1px solid black;color: white}QMenu::item:selected {background-color: black }");