Получение координат клика мыши

main
Артём Проскурнёв 3 years ago
parent 55d498183d
commit e5d6b2ef60
  1. 13
      main.cpp
  2. 10
      qtsgraph.cpp
  3. 8
      qtsgraph.h

@ -44,6 +44,17 @@ void QTSGraph::PaintBox()
SetPenStyle(5);
SetFillStyle(1, clMagenta);
Ellipse(250, 280, 350, 320);
TPixel p;
while(ReadMouseButton() != 2)
{
p = ReadMousePosition();
SetColor(clBlack);
SetPenStyle(1, 1);
SetFillStyle(1, clWhite);
Rectangle(10, 10, 100, 100);
SetTextStyle(16, 0, 0);
OutTextXY(30, 30, std::to_string(p.x));
OutTextXY(30, 60, std::to_string(p.y));
}
// Конец рисования
}

@ -184,6 +184,15 @@ int QTSGraph::ReadMouseButton()
return t;
}
TPixel QTSGraph::ReadMousePosition()
{
TPixel t;
t.x = LastMouseClickPosition.x();
t.y = LastMouseClickPosition.y();
t.color = GetPixel(t.x, t.y);
return t;
}
void QTSGraph::Rectangle(int x1, int y1, int x2, int y2)
{
QPainter painter(&Canvas);
@ -316,6 +325,7 @@ void QTSGraph::paintEvent(QPaintEvent *event)
void QTSGraph::mousePressEvent(QMouseEvent *event)
{
ResetTimer->stop();
LastMouseClickPosition = event->pos();
EventMouseClicked = true;
if (event->buttons() & Qt::LeftButton)
{

@ -61,6 +61,12 @@ along with Vesi. If not, see <http://www.gnu.org/licenses/>.
#define clMagenta 0xFF00FF
#define clCyan 0x00FFFF
struct TPixel
{
int x, y;
unsigned int color;
};
class QTSGraph : public QMainWindow
{
Q_OBJECT
@ -85,6 +91,7 @@ public:
void PutPixel(int x, int y, QRgb c = 0x00000000, int PenWidth = 1);
int ReadKey();
int ReadMouseButton();
TPixel ReadMousePosition();
void Rectangle(int x1, int y1, int x2, int y2);
void SetColor(const QColor &c = Qt::black);
void SetColor(const QRgb c = 0x00000000);
@ -138,6 +145,7 @@ private:
int IDMouseButton = -1;
int ResetInterval;
int TextDirection = 0;
QPoint LastMouseClickPosition;
QBrush Brush;
QPixmap Canvas;

Loading…
Cancel
Save