SHARE
TWEET

pruebas

a guest Aug 8th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "myview.h"
  2. #include "QDebug"
  3. #include <QTimer>
  4.  
  5. MyView::MyView()
  6. {
  7.     sc = new QGraphicsScene();
  8.     this->setSceneRect(0,0,800,600);
  9.     this->setFixedSize(800,600);
  10.     //this->setStyleSheet("QScrollBar {height:0px;}");
  11.     //this->setStyleSheet("QScrollBar {width:0px;}");
  12.     sc->setSceneRect(0,0,800,600);
  13.     this->setScene(sc);
  14.     drawBoard(QPoint (80,80),5,3,54,54);
  15.  
  16. }
  17.  
  18. void MyView::drawBoard(QPoint origin, int boardSize, int lineWidth, int tileWidth, int tileHeight)
  19. {
  20.     QPen line(Qt::black,lineWidth);
  21.     QPoint botRight(origin.x()+boardSize*lineWidth+(boardSize-1)*tileWidth,origin.y()+boardSize*lineWidth+(boardSize-1)*tileHeight);
  22.     qDebug() << botRight;
  23.     //drawing horizontal lines
  24.     for(int i=0;i<boardSize;i++){
  25.         sc->addLine(origin.x(),origin.y()+lineWidth*i+tileHeight*i,botRight.x()-lineWidth,origin.y()+lineWidth*i+tileHeight*i,line);
  26.     }
  27.     //drawing vertical lines
  28.     for(int i=0;i<boardSize;i++){
  29.         sc->addLine(origin.x()+lineWidth*i+tileHeight*i,origin.y(),origin.x()+lineWidth*i+tileHeight*i,botRight.y()-lineWidth,line);
  30.     }
  31. }
  32.  
  33. void MyView::mousePressEvent(QMouseEvent *event)
  34. {
  35.     qDebug() << event->pos();
  36.     /*sc->addEllipse(event->x(),event->y(),10,10,QPen(),QBrush(Qt::red));
  37.     QPoint p(event->y(),event->x());
  38.     QTimer::singleShot(1000, this, [this, p](){
  39.             sc->addEllipse(p.x(),p.y(),10,10,QPen(),QBrush(Qt::blue));
  40.         });
  41. */
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top