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.
#ifndef _BLINKING_ICON_
#define _BLINKING_ICON_
#include <QWidget>
#include <QLabel>
class BlinkingIcon
: public QWidget{
Q_OBJECT
public:
BlinkingIcon
(QWidget * parent
= 0);
virtual ~BlinkingIcon();
private:
}
#endif
{
this->setWindowTitle(tr("My Blinking Icon"));
this->resize(200, 200);
display_image
= new QLabel(this);
display_image
->setPixmap
(QPixmap("c:/my_image.png"));
display_image->adjustSize();
}
BlinkingIcon::~BlinkingIcon(){}
#ifndef _BLINKING_ICON_
#define _BLINKING_ICON_
#include <QWidget>
#include <QLabel>
class BlinkingIcon : public QWidget
{
Q_OBJECT
public:
BlinkingIcon(QWidget * parent = 0);
virtual ~BlinkingIcon();
private:
QLabel * display_image;
}
#endif
BlinkingIcon::BlinkingIcon(QWidget * parent) : QWidget(parent)
{
this->setWindowTitle(tr("My Blinking Icon"));
this->resize(200, 200);
display_image = new QLabel(this);
display_image->setPixmap(QPixmap("c:/my_image.png"));
display_image->adjustSize();
}
BlinkingIcon::~BlinkingIcon(){}
To copy to clipboard, switch view to plain text mode
For your purposes, you'll probably also want to research QLayouts...
Bookmarks