Home > Software engineering >  Consult a question about qt slot function, why I write slot function can only be run at a time?
Consult a question about qt slot function, why I write slot function can only be run at a time?

Time:09-22

# # ifndef MAINWINDOW_H
# define MAINWINDOW_H

#include
#include
# include


The namespace Ui {
The class MainWindow.
}

The class MainWindow: public QMainWindow
{
Q_OBJECT

Public:
Explicit MainWindow (QWidget * parent=0);
~ MainWindow ();
Void Paint ();
Void Paint_2 ();
Private:
Ui: : MainWindow * Ui;
QImage image;
QString expression;
QString expression_2;
QString expression_3;
Int pointx;
Int pointy.
Protected:
Void paintEvent (QPaintEvent *) {
QPainter painter (this);
Painter. DrawImage (0, 0, image);
}

Private slots:
Void on_pushButton_clicked ();
Void on_pushButton_9_clicked ();

};

# endif//MAINWINDOW_H

# include "mainwindow. H"
# include "ui_mainwindow. H"

MainWindow: : MainWindow (QWidget * parent) :
QMainWindow (parent),
UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);
Image=QImage (600300, QImage: : Format_RGB32); Initialization of//canvas size is 600 * 500, using 32-bit color
QColor backColor=qRgb (255255255);//canvas initialization background color with white
Image. The fill (backColor);//to fill the canvas
//Paint ();
}
Void MainWindow: : Paint ()
{
The UI - & gt; SetupUi (this);
QPainter painter (& amp; Image);
Painter. SetRenderHint (QPainter: : Antialiasing, true);//set the sawtooth pattern, prettier
Pointx=35; Pointy=180;//sure axis starting point coordinates, defined here (35280)
Int width=580 - pointx, height=260;//sure axis width and height defined above the canvas for 600 x300, highly depends on the wide,
//draw the axis coordinate origin (35280)
,20,300 painter. DrawRect (20-50100-50);//outer rectangle, since (5, 5), to the end of the (590290), left around 5 clearance,
Painter. DrawLine (pointx, pointy, width + pointx - 30, pointy);//axis x width is the width
Painter. DrawLine (pointx, pointy - height + 100, pointx, pointy);//axis y height of height
Pointx +=10;
Pointy +=10;
return;
}

Void MainWindow: : Paint_2 ()
{
The UI - & gt; SetupUi (this);
QPainter painter (& amp; Image);
Painter. SetRenderHint (QPainter: : Antialiasing, true);//set the sawtooth pattern, prettier
Pointx=45, pointy=190;//sure axis starting point coordinates, defined here (35280)
Int width=580 - pointx, height=260;//sure axis width and height defined above the canvas for 600 x300, highly depends on the wide,
//draw the axis coordinate origin (35280)
,20,600 painter. DrawRect (20-50300-50);//outer rectangle, since (5, 5), to the end of the (590290), left around 5 clearance,
Painter. DrawLine (pointx, pointy, width + pointx - 30, pointy);//axis x width is the width
Painter. DrawLine (pointx, pointy - height + 100, pointx, pointy);//axis y height of height
return;
}

MainWindow: : ~ MainWindow ()
{
Delete the UI;
}


Void MainWindow: : on_pushButton_clicked ()
{

Expression=UI - & gt; LineEdit - & gt; The text (); The UI - & gt; SetupUi (this);
Paint ();
return;
}

Void MainWindow: : on_pushButton_9_clicked ()
{
The UI - & gt; SetupUi (this);
Expression_2=UI - & gt; LineEdit_2 - & gt; The text ();
Expression_3=UI - & gt; LineEdit_3 - & gt; The text ();
Paint_2 ();
return;
}


  • Related