mkhpad
mkhpad

Reputation: 51

How to execute .css files in Qt?

I am having a .css file (with some button images and background image) instead of using style sheet and had added it to my project.

I don't know how to link the .css file with my button image and background.

If anyone knows how to add it please get me some sample or examples for it.

Upvotes: 1

Views: 842

Answers (1)

Tim Meyer
Tim Meyer

Reputation: 12600

You can just read the file in your application and apply it to the whole application (or anything else):

void main( int argc, char* argv[] )
{
    QApplication app( argc, argv );

    QFile styleSheetFile( ":/stylesheet.css" );  // assuming stylesheet is part of the resources
    styleSheetFile.open( QFile::ReadOnly );
    QString styleSheet = styleSheetFile.readAll();

    app->setStyleSheet( styleSheet );
}

Upvotes: 1

Related Questions