9 saveAction =
new QAction(
"Save Image",
this);
10 connect(saveAction, SIGNAL(triggered()),
this, SLOT(on_saveAction_triggered()));
12 this->setPixmap(QPixmap(QSize(0,0)));
17 if(ev->button() == Qt::LeftButton){
18 double c_x = this->width()/2;
19 double c_y = this->height()/2;
20 double img_width = this->pixmap()->width();
21 double img_height = this->pixmap()->height();
22 double send_x = ((ev->x()-c_x+0.0)/img_width);
23 double send_y = ((ev->y()-c_y+0.0)/img_height);
24 if(abs(send_x) > 0.5 || abs(send_y > 0.5))
32 if(ev->button() == Qt::RightButton){
34 m.addAction(saveAction);
35 m.exec(ev->globalPos());
39 void QSmartLabel::on_saveAction_triggered()
41 const QImage _img = this->pixmap()->toImage();
42 QFileInfo file_name(QFileDialog::getSaveFileName(0,
"Img",0,
"PNG (*.png);;BMP (*.bmp);;JPG (*.jpg)"));
43 if(file_name.fileName().isNull()) {
48 _img.save(file_name.absoluteFilePath());
50 else{QMessageBox::information(0, 0,
"Can Not Save Image!!");}
void mouseReleaseEvent(QMouseEvent *ev)
QSmartLabel(QWidget *parent=0)
void sendMouXY(double x, double y)
Sends the mouse coordinate of the image when clicked the image.
void mousePressEvent(QMouseEvent *ev)