Results 1 to 4 of 4

Thread: Setting font throught setStylesheet command

  1. #1
    Join Date
    Jul 2011
    Posts
    31
    Qt products
    Qt3
    Platforms
    MacOS X
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Setting font throught setStylesheet command

    Hi,

    I have already used the designer to give a pushbutton the following stylesheet and tested that it works.

    Qt Code:
    1. border-image: url(:/Images/a.png);
    2. font: 75 13pt "Droid Serif [unknown]";
    3. color:black;
    4. }
    5.  
    6. QPushButton:pressed {
    7. border-image: url(:/Images/b.png);
    8. color: darkred;
    9. }
    To copy to clipboard, switch view to plain text mode 

    I was trying to make sure that if a button is clicked it stays the in the pressed state in terms of color and background image and font so as to give the illusion that it is selected.
    To do this i used the following command in my style sheet.

    Qt Code:
    1. button->setStylesheet(setStyleSheet(QString::fromUtf8("border-image: url(:/Images/b.png);color: darkred;font: 75 13pt;"));
    To copy to clipboard, switch view to plain text mode 
    I dont know where to put the font name ie "Droid Serif [unknown]" as the quotation marks confuse the program if i do it in the same manner as the designer. I have tried appending it as a separate string but it doesnt work. Could anyone give me an example of using the setstylesheet with similar parameters and also setting the font.

    Thanks

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: Setting font throught setStylesheet command

    Escape the quotes ie:
    Qt Code:
    1. pushButton->setStyleSheet(QString::fromUtf8("font: 75 italic 8pt \"MS Sans Serif\";"));
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Spitfire for this useful post:

    qtnewbi3 (24th October 2011)

  4. #3
    Join Date
    Jul 2011
    Posts
    31
    Qt products
    Qt3
    Platforms
    MacOS X
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Setting font throught setStylesheet command

    thank you so much.... noob mistake... i was thinking i had to use the setFont command or something else.... my CSS is horrible...

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 106 Times in 103 Posts

    Default Re: Setting font throught setStylesheet command

    I'm glad I could help

Similar Threads

  1. Setting the Font in a Custom Widget
    By cpsmusic in forum Newbie
    Replies: 5
    Last Post: 14th June 2011, 08:18
  2. How to using/setting the font caching
    By iceman in forum Newbie
    Replies: 5
    Last Post: 28th July 2010, 06:35
  3. QCompleter once again (setting a font)
    By Lykurg in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2007, 13:42
  4. Replies: 3
    Last Post: 30th January 2007, 08:35
  5. Reg - Font setting QListBox
    By lawrence in forum Newbie
    Replies: 1
    Last Post: 23rd December 2006, 21:07

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
  •  
Qt is a trademark of The Qt Company.