MouseClicked() - проверка нажатия кнопки мыши

main
Артём Проскурнёв 4 years ago
parent aafae80a71
commit 212d009d14
  1. 19
      main.cpp
  2. 2
      qtSimpleGraph.pro.user
  3. 18
      qtsgraph.cpp
  4. 12
      qtsgraph.h

@ -9,14 +9,23 @@ int main(int argc, char *argv[])
return a.exec();
}
void QTSGraph::slotstarttimer()
void QTSGraph::slotStartTimer()
{
// Тут рисовать
putpixel(100,100);
delay(2000);
putpixel(300,100);
PutPixel(100,100);
Delay(2000);
PutPixel(300,100);
int x=1;
while(!MouseClicked() && x < 1024)
{
PutPixel(x,50);
x+=1;
Delay(200);
}
// Конец рисования
starttimer->stop();
StartTimer->stop();
}

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.13.3, 2020-12-31T02:48:08. -->
<!-- Written by QtCreator 4.13.3, 2020-12-31T04:27:42. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

@ -1,7 +1,7 @@
#include "qtsgraph.h"
#include "ui_qtsgraph.h"
void QTSGraph::delay(int ms)
void QTSGraph::Delay(int ms)
{
QTime dieTime= QTime::currentTime().addMSecs(ms);
while (QTime::currentTime() < dieTime)
@ -25,9 +25,9 @@ QTSGraph::QTSGraph(int w, int h, int x, int y, QWidget *parent)
this->setWindowTitle("Рисунок");
m_Pixmap = QPixmap(w, h);
m_Pixmap.fill(Qt::white);
starttimer = new QTimer();
connect(starttimer, SIGNAL(timeout()), this, SLOT(slotstarttimer()));
starttimer->start(500);
StartTimer = new QTimer();
connect(StartTimer, SIGNAL(timeout()), this, SLOT(slotStartTimer()));
StartTimer->start(500);
}
QTSGraph::~QTSGraph()
@ -35,7 +35,14 @@ QTSGraph::~QTSGraph()
delete ui;
}
void QTSGraph::putpixel(int x, int y, Qt::GlobalColor c)
bool QTSGraph::MouseClicked()
{
bool m = EventMouseClicked;
EventMouseClicked = false;
return m;
}
void QTSGraph::PutPixel(int x, int y, Qt::GlobalColor c)
{
QPainter painter(&m_Pixmap);
painter.setPen(QPen(QBrush(QColor(c)), 5 ));
@ -51,6 +58,7 @@ void QTSGraph::paintEvent(QPaintEvent *event)
void QTSGraph::mousePressEvent(QMouseEvent *event)
{
EventMouseClicked = true;
if (event->buttons() & Qt::LeftButton)
{
// Левая кнопка

@ -20,18 +20,20 @@ class QTSGraph : public QMainWindow
public:
QTSGraph(int w = 640, int h = 480, int x = -1, int y = -1, QWidget *parent = nullptr);
~QTSGraph();
void putpixel(int x, int y, Qt::GlobalColor c = Qt::red);
void delay(int ms = 1000);
void PutPixel(int x, int y, Qt::GlobalColor c = Qt::red);
void Delay(int ms = 1000);
bool MouseClicked();
private slots:
void slotstarttimer();
void slotStartTimer();
private:
Ui::QTSGraph *ui;
QPixmap m_Pixmap;
QTimer *starttimer;
QTimer *StartTimer;
bool EventMouseClicked = false;
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event) override;
};

Loading…
Cancel
Save