您好,登錄后才能下訂單哦!
#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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。