LouZhang

导航

种类位置信息:geometry

这个主要讲的是各类位置相关函数的区别的

main.cpp

#include "geometry.h"

int main(int argc, char *argv[]){
    QFont font("ZYSong18030",12);
    QApplication::setFont(font);

    QApplication app(argc,argv);
    QTranslator translator(0);
    translator.load("geometry_zh",".");
    app.installTranslator(&translator);
    Geometry *g = new Geometry();
    g->show();
    return app.exec();
}

geometry.h

#ifndef GEOMETRY_H
#define GEOMETRY_H
#include <QtGui>
#include <QApplication>

class Geometry:public QDialog{
    Q_OBJECT
public:
    Geometry();

    QLabel * label1;
    QLabel * label2;
    QLabel * label3;
    QLabel * label4;
    QLabel * label5;
    QLabel * label6;
    QLabel * label7;
    QLabel * label8;
    QLabel * label9;

    QLabel * x_label;
    QLabel * y_label;
    QLabel * frame_geo_label;
    QLabel * pos_label;
    QLabel * geo_label;
    QLabel * width_label;
    QLabel * height_label;
    QLabel * rect_label;
    QLabel * size_label;

    void update_label();
protected:
    void move_event(QMoveEvent*);
    void resize_event(QResizeEvent*);

};

#endif // GEOMETRY_H

geometry.cpp

#include "geometry.h"

Geometry::Geometry(){
    setWindowTitle("geometry");

    label1 = new QLabel;
    label1->setText("x():");
    label2 = new QLabel;
    label2->setText("y():");
    label3 = new QLabel;
    label3->setText("frameGeometry():");
    label4 = new QLabel;
    label4->setText("pos():");
    label5 = new QLabel;
    label5->setText("geometry():");
    label6 = new QLabel;
    label6->setText("width():");
    label7 = new QLabel;
    label7->setText("height():");
    label8 = new QLabel;
    label8->setText("rect():");
    label9 = new QLabel;
    label9->setText("size():");


    x_label = new QLabel;
    y_label = new QLabel;
    frame_geo_label = new QLabel;
    pos_label = new QLabel;
    geo_label = new QLabel;
    width_label = new QLabel;
    height_label = new QLabel;
    rect_label = new QLabel;
    size_label = new QLabel;

    QGridLayout *layout = new QGridLayout(this);
    layout->setMargin(20);
    layout->setSpacing(10);
    int l = 0;
    int c = 1;
    layout->addWidget(label1,0,l);
    layout->addWidget(x_label,0,c);
    layout->addWidget(label2,1,l);
    layout->addWidget(y_label,1,c);
    layout->addWidget(label3,2,l);
    layout->addWidget(frame_geo_label,2,c);
    layout->addWidget(label4,3,l);
    layout->addWidget(pos_label,3,c);
    layout->addWidget(label5,4,l);
    layout->addWidget(geo_label,4,c);
    layout->addWidget(label6,5,l);
    layout->addWidget(width_label,5,c);
    layout->addWidget(label7,6,l);
    layout->addWidget(height_label,6,c);
    layout->addWidget(label8,7,l);
    layout->addWidget(rect_label,7,c);
    layout->addWidget(label9,8,l);
    layout->addWidget(size_label,8,c);

    update_label();
}


void Geometry::update_label(){
    QString tmp;
    QString strx;
    x_label->setText(strx.setNum(x()));

    QString stry;
    y_label->setText(stry.setNum(y()));

    QString frame_geo;
    frame_geo = tmp.setNum(frameGeometry().x()) + "," +
            tmp.setNum(frameGeometry().y()) + "," +
            tmp.setNum(frameGeometry().width()) + "," +
            tmp.setNum(frameGeometry().height());
    frame_geo_label->setText(frame_geo);

    QString position;
    position = tmp.setNum(pos().x()) + "." + tmp.setNum(pos().y());
    pos_label->setText(position);

    QString geo;
    geo = tmp.setNum(geometry().x()) + "," +
            tmp.setNum(geometry().y()) + "," +
            tmp.setNum(geometry().width()) + "," +
            tmp.setNum(geometry().height());
    geo_label->setText(geo);

    QString w;
    width_label->setText(w.setNum(width()));;
    QString h;
    height_label->setText(h.setNum(height()));

    QString r;
    r = tmp.setNum(rect().x()) + "," +
            tmp.setNum(rect().y()) + "," +
            tmp.setNum(rect().width()) + "," +
            tmp.setNum(rect().height());

    QString s;
    s = tmp.setNum(size().width()) + "," + tmp.setNum(size().height());
    rect_label->setText(s);

}

void Geometry::move_event(QMoveEvent *){
    update_label();
}
void Geometry::resize_event(QResizeEvent *){
    update_label();
}

posted on 2012-07-29 02:00  louzhang_swk  阅读(581)  评论(0编辑  收藏  举报