Results 1 to 3 of 3

Thread: Using a QProxyStyle to resize icons within a toolbar and a QFileDialog instance

  1. #1
    Join Date
    Sep 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Using a QProxyStyle to resize icons within a toolbar and a QFileDialog instance

    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.

    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication::setStyle(new TMProxyStyle);
    4. QApplication *application = new QApplication(argc,argv);
    5. TMWindow *mainwindow = new TMWindow();
    6. mainwindow->show();
    7. return application->exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    My customized proxystyle :

    Qt Code:
    1. class TMProxyStyle: public QProxyStyle
    2. {
    3. public:
    4. int pixelMetric(PixelMetric, const QStyleOption * =NULL,const QWidget * =NULL) const;
    5. };
    6.  
    7. int TMProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *options,const QWidget *widget) const
    8. {
    9. if(metric==QStyle::PM_ToolBarIconSize) return ICONSIZE;
    10. if(metric==QStyle::PM_SmallIconSize) return ICONSIZE;
    11. if(metric==QStyle::PM_LargeIconSize) return ICONSIZE;
    12. return QProxyStyle::pixelMetric(metric,options,widget);
    13. }
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using a QProxyStyle to resize icons within a toolbar and a QFileDialog instance

    For the file dialog it will depend which file dialog is being used.

    By default, if you use the static "get" methods, Qt will try to invoke the platform's file dialog for better integration with the system.
    This is usually an external component and not subject to any application styling (it should look like the dialog of any other application after all).

    If you want control over the dialog on the expense of platform integration, you can use the built-in dialog by passing QFileDialog::DontUseNativeDialog as an Option flag.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Using a QProxyStyle to resize icons within a toolbar and a QFileDialog instance

    Thank you for your answer. Now I understand better how styling is applied.

    Cheers,

Similar Threads

  1. Replies: 5
    Last Post: 8th July 2013, 23:23
  2. Icons on toolbar
    By tndave in forum Newbie
    Replies: 2
    Last Post: 8th July 2010, 02:47
  3. Missing Icons for Menu and Toolbar
    By LostInTheWoods in forum Qt Tools
    Replies: 1
    Last Post: 8th January 2010, 11:42
  4. ToolBar icons hidden in windows
    By giusepped in forum Installation and Deployment
    Replies: 3
    Last Post: 13th January 2009, 15:56
  5. Toolbar & Icons missing
    By raphaelf in forum Qt Tools
    Replies: 2
    Last Post: 27th February 2006, 22:19

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.