////////////////////////main.cpp//////////////////////////////
#include <QApplication>
#include <QtGui>
#include "tom.h"
int right_x, right_y, left_x, left_y;
{
m_drawButton
= new QPushButton("&Load Original Image");
connect(m_drawButton, SIGNAL(clicked()), this, SLOT(refresh()));
mainLayout->addWidget(m_pixmapLabel);
mainLayout->addWidget(m_drawButton);
setLayout(mainLayout);
}
void MyWidget::refresh()
{
pm3.load("image_ori.bmp");
pm3.save("image.bmp", 0, -1);
testDraw();
}
void MyWidget::testDraw()
{
right_x=-1;
right_y=-1;
left_x=9999;
left_y=9999;
pm.load("image.bmp");
m_pixmapLabel->setPixmap(pm);
}
{
if (event->button() == Qt::RightButton)
{
right_x=event->x();
right_y=event->y();
}
if
(event->button() == Qt::LeftButton)
{
left_x=event->x();
left_y=event->y();
}
if ( (right_x - left_x) >=0 && (right_y - left_y >=0) && (left_x !=9999) && (right_x !=-1))
{
pm2.load("image.bmp");
pm2 = pm2.copy(left_x,left_y,right_x,right_y);
pm2.save("image.bmp", 0, -1);
m_pixmapLabel->setPixmap(pm2);
}
else QWidget::mousePressEvent(event
);
}
int main(int argc, char *argv[])
{
MyWidget window;
window.show();
return application.exec();
}
////////////////////////main.cpp//////////////////////////////
#include <QApplication>
#include <QtGui>
#include "tom.h"
int right_x, right_y, left_x, left_y;
MyWidget::MyWidget(QWidget* parent): QWidget(parent)
{
m_pixmapLabel = new QLabel;
m_drawButton = new QPushButton("&Load Original Image");
connect(m_drawButton, SIGNAL(clicked()), this, SLOT(refresh()));
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget(m_pixmapLabel);
mainLayout->addWidget(m_drawButton);
setLayout(mainLayout);
}
void MyWidget::refresh()
{
QPixmap pm3;
pm3.load("image_ori.bmp");
pm3.save("image.bmp", 0, -1);
testDraw();
}
void MyWidget::testDraw()
{
right_x=-1;
right_y=-1;
left_x=9999;
left_y=9999;
QPixmap pm;
pm.load("image.bmp");
m_pixmapLabel->setPixmap(pm);
}
void MyWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton)
{
right_x=event->x();
right_y=event->y();
}
if
(event->button() == Qt::LeftButton)
{
left_x=event->x();
left_y=event->y();
}
if ( (right_x - left_x) >=0 && (right_y - left_y >=0) && (left_x !=9999) && (right_x !=-1))
{
QPixmap pm2;
pm2.load("image.bmp");
pm2 = pm2.copy(left_x,left_y,right_x,right_y);
pm2.save("image.bmp", 0, -1);
m_pixmapLabel->setPixmap(pm2);
}
else QWidget::mousePressEvent(event);
}
int main(int argc, char *argv[])
{
QApplication application(argc, argv);
MyWidget window;
window.show();
return application.exec();
}
To copy to clipboard, switch view to plain text mode
////////////////////////////////////tom.h///////////////////////////////////////
#ifndef TOM_H
#define TOM_H
#include <QtGui>
{
Q_OBJECT
public:
protected:
public slots:
void testDraw();
void refresh();
private:
};
#endif
////////////////////////////////////tom.h///////////////////////////////////////
#ifndef TOM_H
#define TOM_H
#include <QtGui>
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget (QWidget* parent = 0);
protected:
void mousePressEvent(QMouseEvent *event);
public slots:
void testDraw();
void refresh();
private:
QLabel* m_pixmapLabel;
QPushButton* m_drawButton;
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks