Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mac OS X and Qt Stylesheets
Qt 6.12 LTS is out! See what's new in the release blog

Mac OS X and Qt Stylesheets

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi all,

    I have been banging my head on the wall for the past two days trying to use stylesheets on Mac OS X.

    The code below will NOT set the background if the STYLESHEETS macro is defined (-DSTYLESHEETS).
    However, when it is not defined and I use the QPalette approach, it works but this is really not the way I intend to implement what I have to do. Any ideas will be warmly welcome!

    @
    #include <QApplication>
    #include <QFrame>
    #include <QPalette>

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

    QFrame* frame = new QFrame;
    

    #ifdef STYLESHEETS
    frame->setStyleSheet( "background-image: url( 'gnu.png' );" );
    #else
    QPalette p;
    QPixmap bg( "gnu.png" );
    bg = bg.scaled( 800, 400, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
    p.setBrush( frame->backgroundRole(), bg );
    frame->setPalette( p );
    #endif
    frame->show();

    return app.exec();
    

    }
    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Well, after scanning through old code, it turns out that you can't put whitespace in the url()...
      This code will work: @frame->setStyleSheet( "background-image: url('gnu.png');" );@ but this will not: @frame->setStyleSheet( "background-image: url( 'gnu.png' );" );@
      So much time lost...

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved