Results 1 to 20 of 34

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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...?

    Yes, there are a few problems. QPixmap has no on-screen representation. It is purely used for holding and manipulating an image file. Also, when you create a pixmap like this,

    QPixmap pixmap("c:/my_image.png");

    or

    QPixmap pixmap;
    pixmap.load("c:/my_image.png");

    It only has local scope, when the function where its declared ends, the pixmap is destroyed, which does you no good for your intention, besides the fact that a QPixmap is the wrong object to create. That is why you use (class-scope) pointers to objects created on the heap with "new". (See my example below)

    To accomplish what you want to do here, you need to use a QLabel. Something like this should get you started.

    Qt Code:
    1. #ifndef _BLINKING_ICON_
    2. #define _BLINKING_ICON_
    3.  
    4. #include <QWidget>
    5. #include <QLabel>
    6.  
    7. class BlinkingIcon : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. BlinkingIcon(QWidget * parent = 0);
    13. virtual ~BlinkingIcon();
    14.  
    15. private:
    16. QLabel * display_image;
    17. }
    18.  
    19. #endif
    20.  
    21. BlinkingIcon::BlinkingIcon(QWidget * parent) : QWidget(parent)
    22. {
    23. this->setWindowTitle(tr("My Blinking Icon"));
    24. this->resize(200, 200);
    25.  
    26. display_image = new QLabel(this);
    27. display_image->setPixmap(QPixmap("c:/my_image.png"));
    28. display_image->adjustSize();
    29. }
    30.  
    31. BlinkingIcon::~BlinkingIcon(){}
    To copy to clipboard, switch view to plain text mode 

    For your purposes, you'll probably also want to research QLayouts...
    Last edited by JimDaniel; 6th June 2008 at 06:14.

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

    mynahz (8th 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.