通过设置样式,来调节透明度
最重要一行代码: "background-color: rgba(255, 0, 0,50%)”,前3个参数是rgb颜色,第4位是透明度,范围[0%-%100]
mainwindow.h代码如下
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <QSlider>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
private:
QLabel *pLabBgSta;
QSlider *pSlider;
private slots:
void SliderValueChanged(int value);
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
mainwindow.cpp代码如下
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->resize(542,900);
//创建一个QLabel用来显示图片
QLabel *pLabPic = new QLabel(this);
pLabPic->setGeometry(0,0,542,841);
pLabPic->setStyleSheet(