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(); return a.exec();
} }
void QTSGraph::slotstarttimer() void QTSGraph::slotStartTimer()
{ {
// Тут рисовать // Тут рисовать
putpixel(100,100); PutPixel(100,100);
delay(2000); Delay(2000);
putpixel(300,100); 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"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

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

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

Loading…
Cancel
Save