Results 1 to 5 of 5

Thread: set stylesheet for qfiledialog

  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default set stylesheet for qfiledialog

    Is there any way to set stylesheet for QFileDialog?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: set stylesheet for qfiledialog

    Yes, just like any other custom widget.
    Just an example
    Qt Code:
    1. QFileDialog dialog;
    2. dialog.setStyleSheet("QPushButton { background-color: red }");
    3. dialog.show();
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    K4ELO (7th March 2013)

  4. #3
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: set stylesheet for qfiledialog

    Thanks for reply, Yes that worked but when i use it this way:
    Qt Code:
    1. fd.setStyleSheet("QPushButton { background-color: red }");
    2. fd.getSaveFileName(0);
    To copy to clipboard, switch view to plain text mode 

    the style is gone! what happens?

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: set stylesheet for qfiledialog

    getSaveFileName() is a static call, and will by default create a native file dialog, which will not care about stylesheets. You can do this way.

    Force use of non-native file dialogs, but only way to apply stylehseet is to apply on the parent (if dialog does not have a parent, you can apply on the applcation, but be warned about the glabal application of styles.
    Qt Code:
    1. qApp->setStyleSheet("QPushButton { background-color: red }");
    2. QFileDialog::getSaveFileName(0, QString(), QString(), QString(), 0, QFileDialog::DontUseNativeDialog);
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. The following user says thank you to Santosh Reddy for this useful post:

    alizadeh91 (18th January 2013)

  7. #5
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: set stylesheet for qfiledialog

    Thanks, Problem solved

Similar Threads

  1. stylesheet
    By BalaQT in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2010, 07:45
  2. stylesheet question
    By gt.beta2 in forum Newbie
    Replies: 3
    Last Post: 30th January 2009, 16:27
  3. Qt Stylesheet
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2009, 14:48
  4. How to do this with StyleSheet
    By yxmaomao in forum Qt Programming
    Replies: 5
    Last Post: 30th May 2008, 08:54
  5. stylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 11
    Last Post: 27th April 2008, 19:11

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.