How to apply style sheet to a custom widget in PyQt

前端 未结 2 1072
悲&欢浪女
悲&欢浪女 2021-01-31 20:52
# -*- coding: utf-8 -*-

import sys
from PyQt4.QtGui import *  
from PyQt4.QtCore import * 

class MainWindow(QWidget):
    def __init__(self):
        super(MainWindow,         


        
2条回答
  •  春和景丽
    2021-01-31 21:23

    In your project folder add a basic CSS file mystylesheet.css. Mutli-language editors like Atom are best for this type of things. The syntax highlighting works properly if you keep it named a CSS file.

    Then drop the dot; qt knows what you mean.

    mystylesheet.css

    QWidget {
        border: 20px solid black;
        border-radius: 10px;
        background-color: rgb(255, 255, 255);
    }
    
    anyQelement.setStyleSheet(open('mystylesheet.css').read())
    

提交回复
热议问题