#include <QApplication>
#include <QtGui>
{
Q_OBJECT
public:
public slots:
void testDraw();
private:
};
m_pixmap(pixmap)
{
testDraw();
}
void MySlot::testDraw()
{
m_pixmap->fill();
p.setPen(pen);
p.drawPoint(qrand()%390, qrand()%290);
}
#include "main.moc"
int main(int argc, char *argv[])
{
pictureLabel->setPixmap(pm);
MySlot myslot(const_cast<QPixmap*>(pictureLabel->pixmap()));
QObject::connect(button1,
SIGNAL(clicked
()),
&myslot,
SLOT(testDraw
()));
QObject::connect(button1,
SIGNAL(clicked
()), pictureLabel,
SLOT(update
()));
mainLayout->addWidget(pictureLabel);
mainLayout->addWidget(button1);
window.show();
return application.exec();
}
#include <QApplication>
#include <QtGui>
class QObject;
class QPixmap;
class MySlot : public QObject
{
Q_OBJECT
public:
MySlot (QPixmap* pixmap, QObject *parent = 0);
public slots:
void testDraw();
private:
QPixmap* m_pixmap;
};
MySlot::MySlot(QPixmap* pixmap, QObject *parent)
: QObject(parent),
m_pixmap(pixmap)
{
testDraw();
}
void MySlot::testDraw()
{
m_pixmap->fill();
QPainter p(m_pixmap);
QPen pen(Qt::black, 10);
p.setPen(pen);
p.drawPoint(qrand()%390, qrand()%290);
}
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication application(argc, argv);
QWidget window;
QVBoxLayout* mainLayout = new QVBoxLayout(&window);
QPushButton* button1 = new QPushButton("Draw");
QLabel* pictureLabel = new QLabel;
QPixmap pm(400,300);
pictureLabel->setPixmap(pm);
MySlot myslot(const_cast<QPixmap*>(pictureLabel->pixmap()));
QObject::connect(button1, SIGNAL(clicked()), &myslot, SLOT(testDraw()));
QObject::connect(button1, SIGNAL(clicked()), pictureLabel, SLOT(update()));
mainLayout->addWidget(pictureLabel);
mainLayout->addWidget(button1);
window.show();
return application.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks