Hello everyone,
I use Qt5 (5.4.1) to build an application under Linux. My problem concerns the size of icons. When I create a toolbar, after compiling, I got icons too small. I know I can use QToolbar::setIconSize(). And I used it in a first time. But now I have exactly the same problem with the icons displayed by an instance of QFileDialog::getSaveFileName. Thus I decided to write my own QProxyStyle and to load it via QApplication::setStyle(). The size of icons in the toolbar are right but not in the QFileDialog. I thought that QFileDialog inherits the style from the QApplication. I'm wrong. I join my code.
int main(int argc, char **argv)
{
TMWindow *mainwindow = new TMWindow();
mainwindow->show();
return application->exec();
}
int main(int argc, char **argv)
{
QApplication::setStyle(new TMProxyStyle);
QApplication *application = new QApplication(argc,argv);
TMWindow *mainwindow = new TMWindow();
mainwindow->show();
return application->exec();
}
To copy to clipboard, switch view to plain text mode
My customized proxystyle :
class TMProxyStyle: public QProxyStyle
{
public:
};
int TMProxyStyle
::pixelMetric(PixelMetric metric,
const QStyleOption *options,
const QWidget *widget
) const {
if(metric
==QStyle::PM_ToolBarIconSize) return ICONSIZE;
if(metric
==QStyle::PM_SmallIconSize) return ICONSIZE;
if(metric
==QStyle::PM_LargeIconSize) return ICONSIZE;
return QProxyStyle::pixelMetric(metric,options,widget);
}
class TMProxyStyle: public QProxyStyle
{
public:
int pixelMetric(PixelMetric, const QStyleOption * =NULL,const QWidget * =NULL) const;
};
int TMProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *options,const QWidget *widget) const
{
if(metric==QStyle::PM_ToolBarIconSize) return ICONSIZE;
if(metric==QStyle::PM_SmallIconSize) return ICONSIZE;
if(metric==QStyle::PM_LargeIconSize) return ICONSIZE;
return QProxyStyle::pixelMetric(metric,options,widget);
}
To copy to clipboard, switch view to plain text mode
Here is a snapshot of the concerned part of my QFileDialog
QFileDialog-Icons.png
Can you help me ? Where is my error ?
Thank you very much.
Bookmarks