Results 1 to 4 of 4

Thread: QIcon not showing up in QAction in Linux

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QIcon not showing up in QAction in Linux

    Hi,

    I have tried Qt 4.6.2, 4.8.0, and 4.8.1, none of these versions will show QIcon in the QAction. However, Qt 5.0.0 alpha will show the icon.

    The QIcon shows up in QWidgetAction correctly however (see example). This only occurs in Linux. Windows is working fine.

    Can someone please take a look at the code and see what is wrong? You can try any icon and rename it to pick.png at same directory.

    Many thanks!

    PS. I also run Qt's examples, the QIcon does not show up either, such as examples/network/torrent

    Qt Code:
    1. #include <QApplication>
    2. #include <QContextMenuEvent>
    3. #include <QWidgetAction>
    4. #include <QMenu>
    5. #include <QPushButton>
    6. #include <QDebug>
    7.  
    8. class MyWidgetAction : public QWidgetAction {
    9.  
    10. public:
    11.  
    12. MyWidgetAction( QObject* parent ) :
    13. QWidgetAction( parent ) {
    14.  
    15. QPixmap pixmap( "./pick.png" );
    16. QPushButton* w = new QPushButton( QIcon( pixmap ), "" );
    17.  
    18. setDefaultWidget( w );
    19. }
    20.  
    21. };
    22.  
    23. class MyWidget : public QWidget {
    24.  
    25. protected:
    26.  
    27. virtual void contextMenuEvent ( QContextMenuEvent * event ) {
    28.  
    29. QMenu* menu = new QMenu;
    30. menu->setAttribute( Qt::WA_DeleteOnClose, true );
    31.  
    32. QIcon icon( QPixmap( "./pick.png" ) );
    33. QAction* action = new QAction( icon, "Test", this );
    34. menu->addAction( action );
    35.  
    36. MyWidgetAction* wact = new MyWidgetAction( this );
    37. menu->addAction( wact );
    38. connect( wact->defaultWidget(), SIGNAL( clicked() ),
    39. menu, SLOT( hide() ) );
    40.  
    41. menu->popup( event->globalPos() );
    42. }
    43.  
    44. };
    45.  
    46. int main( int argc, char** argv )
    47. {
    48. QApplication app( argc, argv );
    49.  
    50. MyWidget w;
    51. w.resize( 300, 300 );
    52. w.show();
    53.  
    54. return app.exec();
    55.  
    56. }
    To copy to clipboard, switch view to plain text mode 


    Added after 33 minutes:


    I just discover that if I do the following, the QIcon shows up, but all Qt application's windows look werid. Any idea?

    unsetenv GNOME_DESKTOP_SESSION_ID DESKTOP_SESSION
    Last edited by lni; 4th August 2012 at 09:53.

  2. #2
    Join Date
    Apr 2008
    Posts
    104
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QIcon not showing up in QAction in Linux

    Can you check is PNG image loaded? (i.e. pixmap.isEmpty)
    Also try QAction* action = new QAction (QIcon ("path"), "Test", this );

  3. #3
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QIcon not showing up in QAction in Linux

    you are using a relative path to the icon (./pick.png), this path is relative to the exec file, not the dir where the source code are. use the function QString QDir::currentPath () to knows what are the current path using bu the app.

    a better alternative are using qt4 resources systems to store wht images. ( http://doc.trolltech.com/4.0/resources.html)

  4. #4
    Join Date
    Mar 2017
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question Re: QIcon not showing up in QAction in Linux

    I have tried setting it up in the .ui interface through the Action Editor,

    myAction -> Edit... -> Icon: -> on the arrow, Choose File... -> myIcon.png -> OK

    It does load up in the preview above, but does not load during the app run. Is this normal for Linux?

Similar Threads

  1. Replies: 2
    Last Post: 29th August 2012, 17:57
  2. Qicon
    By shihao in forum Qt Programming
    Replies: 11
    Last Post: 15th March 2010, 13:23
  3. Showing QMainWindow without showing a child QWidget
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 09:03
  4. Replies: 2
    Last Post: 31st May 2006, 21:52
  5. Replies: 4
    Last Post: 10th May 2006, 22:37

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.