Using Style Sheets Effectively

Other topics

Setting a UI widget's stylesheet

You can set the desired UI widget's stylesheet using any valid CSS. The example below will set a QLabel's text color a border around it.

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{    
    ui->setupUi(this);
    QString style = "color: blue; border: solid black 5px;";
    ui->myLabel->setStylesheet(style); //This can use colors RGB, HSL, HEX, etc.
}

MainWindow::~MainWindow()
{
    delete ui;
}

Contributors

Topic Id: 5931

Example Ids: 20811

This site is not affiliated with any of the contributors.