Results 1 to 20 of 34

Thread: make a .jpg or .bmp picture into a widget...?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #25
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: make a .jpg or .bmp picture into a widget...?

    Okay, I finally whipped up a test app, and found some problems. Here is the working program:

    Qt Code:
    1. #ifndef BLINKINGICON_H
    2. #define BLINKINGICON_H
    3.  
    4. #include <QtGui>
    5. #include <QtCore>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget * parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. public slots:
    16. void startBlinking();
    17.  
    18. private:
    19. QLabel * m_display_image;
    20. };
    21.  
    22. #endif // BLINKINGICON_H
    23.  
    24.  
    25. #include "blinkingicon.h"
    26.  
    27. BlinkingIcon::BlinkingIcon(QWidget * parent) : QWidget(parent)
    28. {
    29. this->setWindowTitle(tr("My Blinking Icon"));
    30. this->setFixedSize(50, 50);
    31.  
    32. m_display_image = new QLabel(this);
    33. m_display_image->setScaledContents(true);
    34.  
    35. this->startBlinking();
    36.  
    37. QTimer * timer = new QTimer(this);
    38. connect(timer, SIGNAL(timeout()), this, SLOT(startBlinking()));
    39. timer->start(1000);
    40. }
    41.  
    42. BlinkingIcon::~BlinkingIcon()
    43. {}
    44.  
    45. void BlinkingIcon::startBlinking()
    46. {
    47. static bool on = false;
    48.  
    49. m_display_image->clear();
    50.  
    51. if (on)
    52. {
    53. m_display_image->setPixmap(QPixmap("C:/my_second_image.png"));
    54. on = false;
    55. }
    56. else
    57. {
    58. m_display_image->setPixmap(QPixmap("C:/my_first_image.png"));
    59. on = true;
    60. }
    61.  
    62. m_display_image->resize(50, 50);
    63. }
    To copy to clipboard, switch view to plain text mode 

    The first problem was that in your header file, you need to put your slot methods under:

    public slots:

    (or protected/private, depending who you want to be able to call)

    After I changed that it worked fine, although sometimes the timer.second() test you were doing would not work as expected, so I changed the test to what you see now...
    Last edited by JimDaniel; 11th June 2008 at 15:28.

  2. The following user says thank you to JimDaniel for this useful post:

    mynahz (12th June 2008)

Similar Threads

  1. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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
  •  
Qt is a trademark of The Qt Company.