Qt - 获取QPushButton图标名称

Max*_*ter 1 c++ icons qt qpushbutton

我有两个状态QPushButton.我想将图标与每个州相关联.

就像音乐播放器中的播放|暂停按钮一样.

为此,我想获取当前的图标名称,以便知道下一个要设置的图标是什么.

我可以继承QPushButton,但它值得吗?

Pri*_*eys 7

相反,设置基础上的图标QPushButton的状态下,设置一个QIcon具有两个状态,如果你有一个可检查的使用它的Qt将选择正确的图标QPushButton.

QIcon icon = QIcon();
// 'Off' state corresponds to unchecked state of QPushButton
icon.addPixmap( QPixmap( ":/img/play.png" ), QIcon::Normal, QIcon::Off );
// 'On' state corresponds to checked state of QPushButton
icon.addPixmap( QPixmap( ":/img/pause.png" ), QIcon::Normal, QIcon::On );
QPushButton * button = new QPushButton();
button->setIcon( icon );
button->setCheckable( true );
Run Code Online (Sandbox Code Playgroud)