qt QSS样式使用方法

头文件添加:

private:
    Ui::MainWindow *ui;
        QFile *qssFile;
        int id1,id2,id3;

 

构造函数中:

 qssFile= new QFile(":/new/qss/aa.qss",this);
    qssFile->open(QFile::ReadOnly);
    QString style_sheet=QString(qssFile->readAll());
    qApp->setStyleSheet(style_sheet);
    qssFile->close();

 

添加资源文件方法:

https://blog.csdn.net/txwtech/article/details/127043688?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169862425016800211577405%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=169862425016800211577405&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-127043688-null-null.nonecase&utm_term=qss&spm=1018.2226.3001.4450

aa.qss

QMainWindow
{
  border-image:url(:/new/image/imgs/p3.png);
}

QPushButton
{
 background-color:rgba(100,225,100,120);
 border-style:outset;
 border-width:4px;
 border-radius:10px;
 border-color:rgba(255,255,255,30);
 font:bold 18px;XX
 color:rgba(255,255,255,0);
 padding:6px;
 }
 QPushButton:hover
 {
   background-color:rgba(100,255,100,100);
   border-color:rgba(225,225,225,200);
   color:rgba(0,0,0,100);
 }
 QPushButton:pressed
 {
  background-color:rgba(100,255,100,200);
  border-color:rgba(255,255,255,30);
  border-style:inset;
  color:rgba(0,0,0,100);
 }
 QSlider::handle:horizontal
 {
   image:url(:/image/sliderHandle.png);
 }
 QSlider::sub-page:horizontal
 {
   border-image:url(:/image/slider.png);
 }

 

posted @ 2023-10-30 08:11  txwtech  阅读(20)  评论(0编辑  收藏  举报