当前位置: 首页 > news >正文

小网站要备案吗免费创建网站的软件

小网站要备案吗,免费创建网站的软件,个人网站做打赏流程,做的网站怎么样才能再网上看到自定义QGraphicsItem和QGraphicsView 说明示例myitem.hmyitem.cppmyview.hmyview.cpp调用main.cpp 效果 说明 在使用Qt的图形视图框架实现功能时#xff0c;一般会在其基础上进行自定义功能实现。 如#xff1a;滚轮对场景的缩放#xff0c;鼠标拖动场景中的项#xff0c;… 自定义QGraphicsItem和QGraphicsView 说明示例myitem.hmyitem.cppmyview.hmyview.cpp调用main.cpp 效果 说明 在使用Qt的图形视图框架实现功能时一般会在其基础上进行自定义功能实现。 如滚轮对场景的缩放鼠标拖动场景中的项以及可以在场景中进行右键操作等。 示例 myitem为自定义QGraphicsItem实现了边框、重绘事件、鼠标悬停、按键、右键菜单等功能。 myitem.h #ifndef MYITEM_H #define MYITEM_H#include QGraphicsItemclass MyItem : public QGraphicsItem { public:MyItem();// 边框virtual QRectF boundingRect() const override;// 重绘事件virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) override;// 设置笔刷inline void setColor(const QColor color) {brushColor color;}protected:// 鼠标按下函数设置被点击的图形项得到焦点并改变光标外观virtual void keyPressEvent(QKeyEvent *event) override;// 键盘按下函数判断是不是向下方向键若是是则向下移动图形项virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;// 悬停事件函数设置光标外观和提示virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;// 右键菜单函数为图形项添加一个右键菜单virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;private:QColor brushColor; // 笔刷颜色 }; #endif // MYITEM_Hmyitem.cpp #include myitem.h #include QPainter #include QCursor #include QKeyEvent #include QGraphicsSceneHoverEvent #include QGraphicsSceneContextMenuEvent #include QMenu#define WIDTH 40 #define HEIGHT 40#define POS 20MyItem::MyItem() {brushColor Qt::black;setFlag(QGraphicsItem::ItemIsFocusable);setFlag(QGraphicsItem::ItemIsMovable);setAcceptHoverEvents(true);}QRectF MyItem::boundingRect() const {qreal adjust 0.5; // 返回上下左右0.5个像素return QRectF(-POS - adjust, -POS - adjust,WIDTH adjust, HEIGHT adjust); }void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget *) {if (hasFocus()) {painter-setPen(QPen(QColor(255, 255, 255)));} else {painter-setPen(QPen(QColor(100, 100, 100)));}painter-setBrush(brushColor);painter-drawRect(-POS, -POS, WIDTH, HEIGHT); }void MyItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {setFocus();// 设置光标为手握下的形状setCursor(Qt::ClosedHandCursor);QGraphicsItem::mousePressEvent(e); }void MyItem::keyPressEvent(QKeyEvent *event) {if (Qt::Key_Down event-key())moveBy(0, 10);else if(Qt::Key_Up event-key())moveBy(0, -10);else if(Qt::Key_Left event-key())moveBy(-10, 0);else if(Qt::Key_Right event-key())moveBy(10, 0);else{}QGraphicsItem::keyPressEvent(event); }void MyItem::hoverEnterEvent(QGraphicsSceneHoverEvent *) {// 设置光标为手张开的形状setCursor(Qt::OpenHandCursor);setToolTip(click me); }void MyItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {QMenu menu;QAction *moveAction menu.addAction(move origin);QAction *selectedAction menu.exec(event-screenPos());if (selectedAction moveAction) {setPos(0, 0);} } myview.h myview继承QGraphicsView重新实现了滚轮事件可对场景进行缩放操作 #ifndef MYVIEW_H #define MYVIEW_H#include QObject #include QGraphicsViewclass MyView : public QGraphicsView {Q_OBJECT public:explicit MyView(QWidget *parent 0);protected:// 滚轮事件缩放virtual void wheelEvent(QWheelEvent *event) override; }; #endif // MYVIEW_H myview.cpp #include myview.h#include myview.h #include QKeyEventMyView::MyView(QWidget *parent) :QGraphicsView(parent) { }void MyView::wheelEvent(QWheelEvent *event) {if(event-delta() 0){scale(1.1, 1.1);}else{scale(0.9, 0.9);}// 加上这个否则在场景和图形项中就没法再接收到该事件了QGraphicsView::wheelEvent(event); } 调用 main.cpp #include QApplication#include myitem.h #include myview.h #include QTime #include QtMath#include QDebugint main(int argc, char* argv[ ]) {QApplication app(argc, argv);qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));QGraphicsScene scene;// 设置场景尺寸减少动态渲染scene.setSceneRect(-300, -225, 600, 450);// 创建项for (int i 0; i 5; i) {MyItem *item new MyItem;item-setColor(QColor(qrand() % 256, qrand() % 256, qrand() % 256));item-setPos(i * 50 - 100, -50);scene.addItem(item);}// 声明视图MyView view;view.setScene(scene);// 设置背景刷view.setBackgroundBrush(QBrush(QColor(220, 220, 220)));view.show();return app.exec(); }效果 显示效果如下 自定义图形视图
http://www.pierceye.com/news/346272/

相关文章:

  • 做网站如何让盈利wordpress链接样式表
  • 网站建设与管理计划谷歌浏览器官网下载手机版
  • 做请帖的网站上海阳性增多
  • 有回定ip怎么做网站青岛建设集团招聘信息网站
  • 淘宝内部卷网站怎么做智慧团建网站登录忘记密码
  • 网站建设前十名建站系统cms
  • 第三方网站开发的商家厦门广告公司网站建设
  • 网站建设基础条件临猗网站制作
  • 建设博客网站步骤常州网站建设百科
  • 门户网站 管理系统wordpress 微信图标
  • 广元网站建设广元莱芜论坛二手车
  • 山东省建设工程质量监督网站广州软件合作中心
  • 郑州网站建设怎么样通州建设局网站
  • 免费网站建设福州怎么修改网站主页
  • 深圳企业建站设计公司wordpress不显示样式
  • 外贸网站商城广东省建设协会网站
  • 杭州制作企业公司网站wordpress数据库添加用户
  • 主域名进入网站广告标识标牌制作厂家
  • 网站建设基础流程摘要专题网站建设策划
  • 滁州网站建设电话网站建设与网站优化
  • 慈溪做网站公司哪家好淘宝商城的网站建设
  • 安徽建设厅网站怎么打不开太原网络搭建
  • idea 网站开发最好的免费推广平台
  • 专业排名优化网站怎么建网站教程视频app
  • 全国八大员报名官方网站支付宝小程序开发工具
  • 怎么查看vps网站服务器时间中国建设会计协会网站
  • 门户网站上的广告怎么做深圳服装网站建设
  • 公司网站上线的通知抚州营销型网站建设
  • 中国住房城乡和城乡建设部网站小广告文案
  • 做带字头像的网站wordpress 翻页设置