lni
4th August 2012, 10:53
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
#include <QApplication>
#include <QContextMenuEvent>
#include <QWidgetAction>
#include <QMenu>
#include <QPushButton>
#include <QDebug>
class MyWidgetAction : public QWidgetAction {
public:
MyWidgetAction( QObject* parent ) :
QWidgetAction( parent ) {
QPixmap pixmap( "./pick.png" );
QPushButton* w = new QPushButton( QIcon( pixmap ), "" );
setDefaultWidget( w );
}
};
class MyWidget : public QWidget {
protected:
virtual void contextMenuEvent ( QContextMenuEvent * event ) {
QMenu* menu = new QMenu;
menu->setAttribute( Qt::WA_DeleteOnClose, true );
QIcon icon( QPixmap( "./pick.png" ) );
QAction* action = new QAction( icon, "Test", this );
menu->addAction( action );
MyWidgetAction* wact = new MyWidgetAction( this );
menu->addAction( wact );
connect( wact->defaultWidget(), SIGNAL( clicked() ),
menu, SLOT( hide() ) );
menu->popup( event->globalPos() );
}
};
int main( int argc, char** argv )
{
QApplication app( argc, argv );
MyWidget w;
w.resize( 300, 300 );
w.show();
return app.exec();
}
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
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
#include <QApplication>
#include <QContextMenuEvent>
#include <QWidgetAction>
#include <QMenu>
#include <QPushButton>
#include <QDebug>
class MyWidgetAction : public QWidgetAction {
public:
MyWidgetAction( QObject* parent ) :
QWidgetAction( parent ) {
QPixmap pixmap( "./pick.png" );
QPushButton* w = new QPushButton( QIcon( pixmap ), "" );
setDefaultWidget( w );
}
};
class MyWidget : public QWidget {
protected:
virtual void contextMenuEvent ( QContextMenuEvent * event ) {
QMenu* menu = new QMenu;
menu->setAttribute( Qt::WA_DeleteOnClose, true );
QIcon icon( QPixmap( "./pick.png" ) );
QAction* action = new QAction( icon, "Test", this );
menu->addAction( action );
MyWidgetAction* wact = new MyWidgetAction( this );
menu->addAction( wact );
connect( wact->defaultWidget(), SIGNAL( clicked() ),
menu, SLOT( hide() ) );
menu->popup( event->globalPos() );
}
};
int main( int argc, char** argv )
{
QApplication app( argc, argv );
MyWidget w;
w.resize( 300, 300 );
w.show();
return app.exec();
}
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