#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><h3>(%1, %2)<h3></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(); }
上传个图真麻烦
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。