⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw.cxx

📁 基于网络编程的例子
💻 CXX
字号:
// Draw.cxx//// Simple example showing Qt's event methods that are inhereted from QWidget//// This example is derived from the QT connect.cpp example, so the following// copyright is in effect:/****************************************************************************** $Id: qt/examples/drawlines/connect.cpp   2.2.0   edited 2000-08-31 $**** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.**** This file is part of an example program for Qt.  This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "draw.hxx"#include <stdlib.h>#include <stdio.h>const int MAXPOINTS = 3000;  // maximum number of pointsDrawWidget::DrawWidget(QWidget *parent, const char *name)  : QWidget(parent, name){  setBackgroundColor(white);            // white background  count = 0;  points = new QPoint[MAXPOINTS];  color = new QColor(250, 10, 30); // Red, Green, Blue}DrawWidget::~DrawWidget(){  delete[] points;                              // cleanup}void DrawWidget::paintEvent(QPaintEvent *){  QPainter paint(this);  paint.drawText(10, 20, "Click the mouse buttons, or press button and drag");  paint.setPen(*color);  for (int i=0; i<count; i++) {         // connect all points    paint.drawRect(points[i].x()-3, points[i].y()-3, 6, 6);  }}void DrawWidget::mousePressEvent(QMouseEvent * e) {  if (count < MAXPOINTS) {    QPainter paint(this);    points[count] = e->pos();           // add point    paint.setPen(*color);    paint.drawRect(points[count].x()-3, points[count].y()-3, 6, 6);    count++;  }}void DrawWidget::mouseMoveEvent(QMouseEvent *e) {  if (count < MAXPOINTS) {    QPainter paint(this);    points[count] = e->pos();           // add point    paint.setPen(*color);    paint.drawRect(points[count].x()-3, points[count].y()-3, 6, 6);    count++;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -