franco.amato
23rd February 2010, 21:45
Hi I need a QTogggleButton but seems QT doesn't has such widget.
In my case I need to load 2 different icons. I would implement a play/pause button so I need to toggle between the > and || images.
How can I do?
Best Regards,
Franco
janorcutt
23rd February 2010, 21:51
you can use a tool button and implement something like so:
void MainWindow::playPause()
{
QIcon icon1;
QIcon icon2;
icon1.addFile(QString::fromUtf8(":icons/icons/media_playback_pause"), QSize(),QIcon::Normal, QIcon::On);
icon2.addFile(QString::fromUtf8(":icons/icons/media_playback_start"), QSize(),QIcon::Normal, QIcon::On);
if(mediaObject->state() == Phonon::StoppedState){
mediaObject->play();
} else {
if(mediaObject->state() == Phonon::PlayingState){
mediaObject->pause();
ui->toolButton_4->setIcon(icon2);
ui->label_2->setText("Paused");
} else {
if(mediaObject->state() == Phonon::PausedState){
mediaObject->play();
ui->label_2->setText("Playing");
ui->toolButton_4->setIcon(icon1);
}
}
}
}
void MainWindow::stop()
{
QIcon icon;
icon.addFile(QString::fromUtf8(":icons/icons/media_playback_start"), QSize(),QIcon::Normal, QIcon::On);
mediaObject->stop();
ui->toolButton_4->setIcon(icon);
ui->label_2->setText("Stopped");
ui->label->setText("00:00");
}
hope it helps
schnitzel
23rd February 2010, 22:11
or you can do it easily in Qt Creator by assigning different bitmaps for the different states
4325
and make the button checkable. The different bitmaps are stored in a qrc file.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.