Is there any way to set stylesheet for QFileDialog?
Is there any way to set stylesheet for QFileDialog?
Yes, just like any other custom widget.
Just an example
Qt Code:
QFileDialog dialog; dialog.setStyleSheet("QPushButton { background-color: red }"); 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.
K4ELO (7th March 2013)
Thanks for reply, Yes that worked but when i use it this way:
Qt Code:
QFileDialog fd; fd.setStyleSheet("QPushButton { background-color: red }"); fd.getSaveFileName(0);To copy to clipboard, switch view to plain text mode
the style is gone! what happens?
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:
qApp->setStyleSheet("QPushButton { background-color: red }"); 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.
alizadeh91 (18th January 2013)
Thanks, Problem solved
Bookmarks