#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void ButtonSlot();
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
Ui::MainWindow *ui;
QString str;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
#include <QLabel>
#include <QPainter>
#include <QMouseEvent>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(ButtonSlot()));//连接信号和槽
}
MainWindow::~MainWindow()//析构函数
{
delete ui;
}
void MainWindow::ButtonSlot()
{
str=ui->lineEdit->text();
ui->textBrowser->setText(str);
}//把lineEdit内容放到Browser
void MainWindow::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.drawText(170,75,"坐标-》" );
}//用painter随便写点啥
void MainWindow::mousePressEvent(QMouseEvent *event)
{
ui->label->setText(QString("<center><h2>(%1, %2)<h2></center>")
.arg(QString::number(event->x()), QString::number(event->y())));
}//坐标显示到label
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
上传个图真麻烦
转载于:https://blog.51cto.com/kayseloyyy/1971427