结果预览:
一.代码5个文件
//glwidget.h #ifndef GLWIDGET_H #define GLWIDGET_H #include <QGLWidget> class GLWidget:public QGLWidget { Q_OBJECT public: explicit GLWidget(QWidget *parent = 0); int xRotation() const { return xRot; } int yRotation() const { return yRot; } int zRotation() const { return zRot; } signals: void xRotationChanged( int angle); void yRotationChanged( int angle); void zRotationChanged( int angle); public slots: void setXRotation(int angle); void setYRotation(int angle); void setZRotation(int angle); protected: void initializeGL(); void paintGL(); void resizeGL(int w, int h); void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); private slots: void alwaysRotate(); void drawTriangle(); private: void normalizeAngle(int &angle); int xRot; int yRot; int zRot; QColor faceColors[4]; QPoint lastPos; QColor qtGreen, qtPurple; }; #endif