matlab精准鼠标取点 二维图像,QQuickPaintedItem鼠标精准拾取(pick/select)研究

#include

"CustomItem.h"

#include

#include

#include

CustomItem::CustomItem(QQuickItem *parent)

: QQuickPaintedItem(parent)

{

setAcceptedMouseButtons(Qt::LeftButton

| Qt::RightButton

| Qt::MiddleButton);

setFlag(QQuickItem::ItemHasContents);

}

QString CustomItem::name()

const

{

return

m_name;

}

void

CustomItem::setName(

const

QString &name)

{

m_name = name;

}

QColor CustomItem::color()

const

{

return

m_color;

}

void

CustomItem::setColor(

const

QColor &color)

{

m_color = color;

}

void

CustomItem::paint(QPainter *painter)

{

// pen & brush

QPen pen(m_color,

10

);

QLinearGradient gradient;

gradient.setStart(

0

,

50

);

gradient.setFinalStop(

200

,

50

);

gradient.setColorAt(

0

, Qt::blue);

gradient.setColorAt(

0

.

2

, Qt::green);

gradient.setColorAt(

0

.

4

, Qt::red);

gradient.setColorAt(

0

.

6

, Qt::yellow);

gradient.setColorAt(

1

, Qt::cyan);

painter->setPen(pen);

painter->setBrush(gradient);

painter->setRenderHints(QPainter::Antialiasing,

true

);

// Unclosed shape

static

const

QPointF points[

3

] =

{

QPointF(

10

.

0

,

100

.

0

),

QPointF(

20

.

0

,

10

.

0

),

QPointF(

200

.

0

,

50

.

0

),

};

painter->save();

pen.setJoinStyle(Qt::MiterJoin);

// MiterJoin, BevelJoin, RoundJoin

pen.setCapStyle(Qt::RoundCap);

// FlatCap, SquareCap, RoundCap

pen.setStyle(Qt::DashLine);

painter->drawPolyline(points,

3

);

painter->restore();

// Closed shape

QPainterPath path;

path.addEllipse(QRectF(

10

.

0

,

10

.

0

, width() -

10

.

0

, height() -

10

.

0

));

painter->drawPath(path);

/* 三角形

QPainterPath path;

path.moveTo(width() / 2, 0);

path.lineTo(width(), height());

path.lineTo(0, height());

path.lineTo(width() / 2, 0);

painter->fillPath(path, m_color);

*/

}

bool

CustomItem::contains(

const

QPointF &point)

const

{

// Unclosed shape

static

const

QPointF points[

3

] =

{

QPointF(

10

.

0

,

100

.

0

),

QPointF(

20

.

0

,

10

.

0

),

QPointF(

200

.

0

,

50

.

0

),

};

QPainterPath path;

path.moveTo(points[

0

]);

path.lineTo(points[

1

]);

path.lineTo(points[

2

]);

QPainterPathStroker stroker;

stroker.setWidth(

10

);

stroker.setJoinStyle(Qt::MiterJoin);

stroker.setCapStyle(Qt::RoundCap);

stroker.setDashPattern(Qt::SolidLine);

return

stroker.createStroke(path).contains(point);

// Close shape

QPainterPath path;

path.addEllipse(QRectF(

10

.

0

,

10

.

0

, width() -

10

.

0

, height() -

10

.

0

));

QPainterPathStroker stroker;

stroker.setWidth(

10

);

return

path.contains(point) || stroker.createStroke(path).contains(point);

/* 三角形

QPainterPath path;

path.moveTo(width() / 2, 0);

path.lineTo(width(), height());

path.lineTo(0, height());

path.lineTo(width() / 2, 0);

QPainterPathStroker stroker;

stroker.setWidth(10);

return return path.contains(point) || stroker.createStroke(path).contains(point);

*/

}

void

CustomItem::mousePressEvent(QMouseEvent *event)

{

qDebug() <<

"CustomItem::mousePressEvent"

;

QQuickPaintedItem::mousePressEvent(event);

}

void

CustomItem::mouseMoveEvent(QMouseEvent *event)

{

qDebug() <<

"CustomItem::mouseMoveEvent"

;

QQuickPaintedItem::mouseMoveEvent(event);

}

void

CustomItem::mouseReleaseEvent(QMouseEvent *event)

{

qDebug() <<

"CustomItem::mouseReleaseEvent"

;

QQuickPaintedItem::mouseReleaseEvent(event);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
function GRABIT Extracts data points from an image file. % % GRABIT starts a GUI program for extracting data from an image file. % It is capable of reading in BMP, JPG, TIF, GIF, and PNG files (anything % that is readable by IMREAD). Multiple data sets can be extracted from a % single image file, and the data is saved as an n-by-2 matrix variable in % the workspace. It can also be renamed and saved as a MAT file. % % Following steps should be taken: % 1. Load the image file. % 2. Calibrate axes dimensions. You will be prompted to select 4 points % on the image. Zoom and pan enabled. % 3. Grab points by clicking on points. Right-click to delete a point. % Image can be zoomed and panned. % 4. Multiple data sets will remain in memory so long as the GUI is open. % Variables can be renamed, saved to file, or edited in Array Editor. % % Panning is achieved by clicking and dragging on the image. Double-click % to center view. Right click and drag to zoom in and out. In addition, % there are keyboard shortcuts for zooming: % - zoom in % - zoom out % - reset view % % This code will also work for extracting data points from a tilted or a % skewed image (even upside-down or mirrored). The calibration stage % ensures that the imperfect orientation or quality of the image is % accounted for. % % The types of files that will most likely work are BMP, JPG, TIF, GIF (up % to 8-bit), and PNG files. Basically, any format supported by the IMREAD % is accepted. % % GRABIT(FILENAME) will start the GUI program and open the image file % FILENAME.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值