31.QT坐标系

  • dialog.h
     1 #ifndef DIALOG_H
     2 #define DIALOG_H
     3 
     4 #include <QDialog>
     5 #include <QLabel>
     6 #include <QGridLayout>
     7 #include <QMouseEvent>
     8 #include <QEvent>
     9 
    10 namespace Ui {
    11 class Dialog;
    12 }
    13 
    14 class Dialog : public QDialog
    15 {
    16     Q_OBJECT
    17 
    18 public:
    19     explicit Dialog(QWidget *parent = 0);
    20     ~Dialog();
    21 
    22 private:
    23     Ui::Dialog *ui;
    24 
    25     void moveEvent(QMoveEvent *event);
    26     void resizeEvent(QResizeEvent *event);
    27 
    28 public:
    29     void show1();
    30 };
    31 
    32 #endif // DIALOG_H

     

  • dialog.cpp
     1 #include "dialog.h"
     2 #include "ui_dialog.h"
     3 #include <QDebug>
     4 
     5 Dialog::Dialog(QWidget *parent) :
     6     QDialog(parent),
     7     ui(new Ui::Dialog)
     8 {
     9     ui->setupUi(this);
    10 }
    11 
    12 Dialog::~Dialog()
    13 {
    14     delete ui;
    15 }
    16 
    17 void Dialog::moveEvent(QMoveEvent *event)
    18 {
    19     qDebug() << "1234"<<endl;
    20     show1();
    21 }
    22 
    23 void Dialog::resizeEvent(QResizeEvent *event)
    24 {
    25     qDebug() << "1234"<<endl;
    26     show1();
    27 }
    28 
    29 void Dialog::show1()
    30 {
    31     QString infoall;
    32     QString x;
    33     x.sprintf("x()=%d",this->x());
    34     infoall = infoall +x + "\r\n";
    35 
    36     QString y;
    37     y.sprintf("y()=%d",this->y());
    38     infoall = infoall +y + "\r\n";
    39 
    40     QString width;
    41     width.sprintf("width=%d",this->width());
    42     infoall = infoall +width + "\r\n";
    43 
    44     QString height;
    45     height.sprintf("height=%d",this->height());
    46     infoall = infoall +height + "\r\n";
    47     ui->textEdit->setText(infoall);
    48 }

     

posted @ 2018-04-11 10:17  喵小喵~  阅读(212)  评论(0)    收藏  举报