Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44952
  • 博文数量: 12
  • 博客积分: 325
  • 博客等级: 一等列兵
  • 技术积分: 170
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-02 12:08
文章分类

全部博文(12)

文章存档

2012年(12)

我的朋友

分类: LINUX

2012-09-20 14:16:24

geometry.h

点击(此处)折叠或打开

  1. #ifndef GEOMETRY_H
  2. #define GEOMETRY_H
  3. #include <QtGui>
  4. class Geometry : public QDialog
  5. {
  6. Q_OBJECT
  7. public:
  8. Geometry();
  9. QLabel *label1;
  10. QLabel *label2;
  11. QLabel *label3;
  12. QLabel *label4;
  13. QLabel *label5;
  14. QLabel *label6;
  15. QLabel *label7;
  16. QLabel *label8;
  17. QLabel *label9;
  18. QLabel *xLabel;
  19. QLabel *yLabel;
  20. QLabel *frameGeoLabel;
  21. QLabel *posLabel;
  22. QLabel *geoLabel;
  23. QLabel *widthLabel;
  24. QLabel *heightLabel;
  25. QLabel *rectLabel;
  26. QLabel *sizeLabel;
  27. void updateLabel();
  28. protected:
  29. void moveEvent(QMoveEvent *);
  30. void resizeEvent(QResizeEvent *);
  31. };
  32. #endif // GEOMETRY_H


 

geometry.cpp


点击(此处)折叠或打开

  1. #include "geometry.h"
  2. Geometry::Geometry()
  3. {
  4.     setWindowTitle(tr("Geometry"));
  5.     label1 = new QLabel;
  6.     label1->setText("x():");
  7.     label2 = new QLabel;
  8.     label2->setText("y():");
  9.     label3 = new QLabel;
  10.     label3->setText("frameGeometry():");
  11.     label4 = new QLabel;
  12.     label4->setText("pos():");
  13.     label5 = new QLabel;
  14.     label5->setText("geometry():");
  15.     label6 = new QLabel;
  16.     label6->setText("width():");
  17.     label7 = new QLabel;
  18.     label7->setText("height():");
  19.     label8 = new QLabel;
  20.     label8->setText("rect():");
  21.     label9 = new QLabel;
  22.     label9->setText("size():");
  23.     xLabel = new QLabel;
  24.     yLabel = new QLabel;
  25.     frameGeoLabel = new QLabel;
  26.     posLabel = new QLabel;
  27.     geoLabel = new QLabel;
  28.     widthLabel = new QLabel;
  29.     heightLabel = new QLabel;
  30.     rectLabel = new QLabel;
  31.     sizeLabel = new QLabel;
  32.     QGridLayout *layout = new QGridLayout(this);
  33.     layout->setMargin(20);
  34.     layout->setSpacing(10);
  35.     int l = 0;
  36.     int c = 1;
  37.     layout->addWidget(label1,0,l);
  38.     layout->addWidget(xLabel,0,c);
  39.     layout->addWidget(label2,1,l);
  40.     layout->addWidget(yLabel,1,c);
  41.     layout->addWidget(label3,2,l);
  42.     layout->addWidget(frameGeoLabel,2,c);
  43.     layout->addWidget(label4,3,l);
  44.     layout->addWidget(posLabel,3,c);
  45.     layout->addWidget(label5,4,l);
  46.     layout->addWidget(geoLabel,4,c);
  47.     layout->addWidget(label6,5,l);
  48.     layout->addWidget(widthLabel,5,c);
  49.     layout->addWidget(label7,6,l);
  50.     layout->addWidget(heightLabel,6,c);
  51.     layout->addWidget(label8,7,l);
  52.     layout->addWidget(rectLabel,7,c);
  53.     layout->addWidget(label9,8,l);
  54.     layout->addWidget(sizeLabel,8,c);
  55.     updateLabel();
  56. }
  57. void Geometry::updateLabel()
  58. {
  59.     QString temp;
  60.     QString str_x;
  61.     xLabel->setText(str_x.setNum(x()));
  62.     QString str_y;
  63.     yLabel->setText(str_y.setNum(y()));
  64.     QString frameGeo;
  65.     frameGeo = temp.setNum(frameGeometry().x()) + ", " + temp.setNum(frameGeometry().y()) + ", " +
  66.         temp.setNum(frameGeometry().width()) + ", " + temp.setNum(frameGeometry().height());
  67.     frameGeoLabel->setText(frameGeo);
  68.     QString position ;
  69.     position = temp.setNum(pos().x()) + ", " + temp.setNum(pos().y());
  70.     posLabel->setText(position);
  71.     QString geo;
  72.     geo = temp.setNum(geometry().x()) + ", " + temp.setNum(geometry().y()) + ", " +
  73.         temp.setNum(geometry().width()) + ", " + temp.setNum(geometry().height());
  74.     geoLabel->setText(geo);
  75.     QString w;
  76.     widthLabel->setText(w.setNum(width()));
  77.     QString h;
  78.     heightLabel->setText(h.setNum(height()));
  79.     QString r;
  80.     r = temp.setNum(rect().x()) + ", " + temp.setNum(rect().y()) + ", " +
  81.         temp.setNum(rect().width()) + ", " + temp.setNum(rect().height());
  82.     rectLabel->setText(r);
  83.     QString s;
  84.     s = temp.setNum(size().width()) + ", " + temp.setNum(size().height());
  85.     sizeLabel->setText(s);
  86. }
  87. void Geometry::moveEvent(QMoveEvent *)
  88. {
  89.     updateLabel();
  90. }
  91. void Geometry::resizeEvent(QResizeEvent *)
  92. {
  93.     updateLabel();
  94. }


main.cpp

点击(此处)折叠或打开

  1. #include "geometry.h"
  2. #include <QApplication>
  3. int main(int argc, char *argv[])
  4. {
  5.     QFont font("ZYSong18030",12);
  6.     QApplication::setFont(font);
  7.     QApplication app(argc,argv);
  8.     QTranslator translator(0);
  9.     translator.load("geometry_zh",".");
  10.     app.installTranslator(&translator);
  11.     Geometry *g = new Geometry();
  12.     g->show();
  13.     return app.exec();
  14. }

运行效果图

image

阅读(791) | 评论(0) | 转发(0) |
0

上一篇:[Qt]标准对话框

下一篇:没有了

给主人留下些什么吧!~~