描画装置は、基本的な座標系を平行移動及び回転変換によって論理演算を座標より容易に得ることができるの物理座標であるQPainterの
ビューポート:矩形領域の任意の物理座標の描画装置は、描画のための矩形領域の物理的な座標を選択することができます。デフォルトのビューポート全体の矩形領域は、描画装置の場合と同じです。
QPaintset :: SETVIEWPORT(int型のx、int型のY、INT幅、int型の高さ)が定義ビューポート
ウィンドウ:矩形領域に対応するビューポートが、論理座標によって定義された座標系であり、中央のウィンドウの中心の直交座標
QPaintset :: SETWINDOW(int型のx、int型のY、INT幅、int型の高さ)
1つの#include " viewport.h " 2の#include " ui_viewport.h " 3の#include <QPainterの> 4の#include <QPen> 5の#include <QBrush> 6の#include <QtMath> 7の#include <QLinearGradient> 8ビューポート::ビューポート(QWidgetの* 親): 9 QWidgetの(親)、 10 UI(新しいUiの::ビューポート) 11 { 12 UI-> setupUi(本) 13 setWindowTitle(" 视口和窗口" )。 14 } 15 16ビューポート::〜ビューポート() 17 { 18は、 UIを削除します。 19 } 20 21 空隙ビューポート:: paintEvent(QPaintEvent * イベント) 22 { 23 QPainterの画家(この)。 24 INT = W 幅()。 25 int型 H = 高さ()。 26 INTの側面= (H、W)QMIN。 27 QRect四角形((W側)/ 2、(H側)/ 2 、側、側)。 28 painter.drawRect(RECT)。 29 painter.setViewport(RECT); // 設定ビューポート 30 painter.setWindow( - 100、 - 100、200は、200である); // ウィンドウの論理座標セット 31は 、painter.setRenderHint(QPainterの::アンチエイリアス) 32 33である QPen PEN。 34は pen.setWidth(2 ); 35 pen.setColor(Qtの::レッド); 36 pen.setStyle(Qtの::実線); 37 painter.setPen(PEN)、 38は 39 qlineargradient linerGrad(0、0、100、0 ); 40 linerGrad.setColorAt(0 、Qtの::イエロー) 41 linerGrad.setColorAt(1 、Qtの::緑色) 42 linerGrad.setSpread(QGradient :: PadSpread)。 43 painter.setBrush(linerGrad)。 44 45 // 设置复合模式 46 painter.setCompositionMode(QPainterの:: RasterOp_SourceXorDestination)。 47 48 のために(int型 i = 0 ; iは< 36 ; iは++ ) 49 { 50 painter.drawEllipse(のQPoint(50、0)、50、50 ); 51である painter.rotate(10); // 円を描いた後に座標系の10度の回転 52は、 53である } 54 }
異なるパラメータが異なる重畳図を得ることができます。