QspinBox
微调框小部件实现不透明度调整
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSpinBox>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
QSpinBox *spinBox;
private slots:
void spinBoxValueChanged(int);
};
#endif
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->setGeometry(0,0,800,480);
this->setStyleSheet("QMainWindow{background-color:"
"rgba(100,100,100,100%)}");
spinBox = new QSpinBox(this);
spinBox->setGeometry(350,200,150,30);
spinBox->setRange(0,100);
spinBox->setSingleStep(10);
spinBox->setValue(100);
spinBox->setSuffix("%不透明度");
connect(spinBox,SIGNAL(valueChanged(int)),this,
SLOT(spinBoxValueChanged(int)));
}
MainWindow::~MainWindow() {}
void MainWindow::spinBoxValueChanged(int opacity)
{
double dobleopacity = (double)opacity/100;
this->setWindowOpacity(dobleopacity);
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}