Results 1 to 5 of 5

Thread: [QT Ctrator] Setting StyleSheeet in code

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default [QT Ctrator] Setting StyleSheeet in code

    Hello!

    I've got a little problem with setting style sheet in my code:

    Qt Code:
    1. this->setStyleSheet(QString("QCheckBox::indicator:unchecked {image: url("APP_PATH"\"/grafqtch/uncheckedbig.png\");}"));
    2. this->setStyleSheet(QString("QCheckBox::indicator:checked {image: url("APP_PATH"\"/grafqtch/checkedbig.png\");}"));
    To copy to clipboard, switch view to plain text mode 

    APP_PATH is a definition with a prefix of my application path (in configuration header file). I want all QCheckBox to have this style. When I put this in graphic editor in style sheet section of my form (without APP_PATH) it works fine but with that path also have problems. Can I somehow use header configuration file while I'm designing form in graphic mode? Or maybe I can set that stylesheet in code in a different way?

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: [QT Ctrator] Setting StyleSheeet in code

    Have a look on how to concat QString: QString::arg() or QString::operator+=.

  3. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT Ctrator] Setting StyleSheeet in code

    Yes, You're right. I've fixed it, and now It works in my code. But one more problem. Can I 'append' somehow my stylesheet? When I set first one, and then the second one in code - only last one works. Is there any other way than crating long QString with all style?

    thanks in advance
    best regards
    Tomasz

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: [QT Ctrator] Setting StyleSheeet in code

    Of course only the last one works because setStyleSheet deletes all previous set ones. Simple create one "big" QString using the mentioned += operator and set all at once.
    Qt Code:
    1. QString css;
    2. css += "foo";
    3. css += "bar";
    4. setStyleSheet(css);
    To copy to clipboard, switch view to plain text mode 

    Or use QString::append().

  5. The following user says thank you to Lykurg for this useful post:

    Tomasz (26th January 2011)

  6. #5
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT Ctrator] Setting StyleSheeet in code

    Thanks! But I thought that maybe there is simpler way to change style, than create one big QString. Thought that each property is treated separately, and I can change just one of it somehow.

    thanks
    best regards
    Tomasz

Similar Threads

  1. Dpi setting on MAC OS X
    By nikhil in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2010, 08:55
  2. Replies: 1
    Last Post: 11th March 2010, 21:30
  3. help setting up qt4 ui from qt3
    By illuzioner in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2007, 04:16
  4. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.