Results 1 to 3 of 3

Thread: QToggleButton

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    620
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QToggleButton

    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
    Franco Amato

  2. #2
    Join Date
    Feb 2010
    Location
    Wokingham, United Kingdom
    Posts
    36
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QToggleButton

    you can use a tool button and implement something like so:

    Qt Code:
    1. void MainWindow::playPause()
    2. {
    3. QIcon icon1;
    4. QIcon icon2;
    5. icon1.addFile(QString::fromUtf8(":icons/icons/media_playback_pause"), QSize(),QIcon::Normal, QIcon::On);
    6. icon2.addFile(QString::fromUtf8(":icons/icons/media_playback_start"), QSize(),QIcon::Normal, QIcon::On);
    7. if(mediaObject->state() == Phonon::StoppedState){
    8. mediaObject->play();
    9. } else {
    10. if(mediaObject->state() == Phonon::PlayingState){
    11. mediaObject->pause();
    12. ui->toolButton_4->setIcon(icon2);
    13. ui->label_2->setText("Paused");
    14. } else {
    15. if(mediaObject->state() == Phonon::PausedState){
    16. mediaObject->play();
    17. ui->label_2->setText("Playing");
    18. ui->toolButton_4->setIcon(icon1);
    19. }
    20. }
    21. }
    22. }
    23.  
    24. void MainWindow::stop()
    25. {
    26. QIcon icon;
    27. icon.addFile(QString::fromUtf8(":icons/icons/media_playback_start"), QSize(),QIcon::Normal, QIcon::On);
    28. mediaObject->stop();
    29. ui->toolButton_4->setIcon(icon);
    30. ui->label_2->setText("Stopped");
    31. ui->label->setText("00:00");
    32. }
    To copy to clipboard, switch view to plain text mode 

    hope it helps

  3. #3
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QToggleButton

    or you can do it easily in Qt Creator by assigning different bitmaps for the different states

    pb.JPG

    and make the button checkable. The different bitmaps are stored in a qrc file.

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.