Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. drawing line with QGraphicsView and QGraphicsscene

drawing line with QGraphicsView and QGraphicsscene

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 3.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    newQter
    wrote on last edited by newQter
    #1

    QGraphicsView, QGraphicsscene,addLine

    Hi, I am new to Qt and I wanted to draw some grid lines in the scene in the constructor as a guide for the user to click and draw shapes.

      c1 = new QGraphicsScene(0,0,400,400,this); 
    
        c1->setSceneRect(0,0,400,400); 
        cv1= new QGraphicsView(c1,this);
    

    Given that both my scene and view are bound by rect 400,400, I want to draw say 10 lines as guide/grid on the scene. It seems if I take c1->height() and c1->wdith(), I can addLines in the scene. But, when I change the size of my application window, the lines do not readjust in cv1. Any easy way to accomplish this?

    Here is the drawGrid routine that is called from the constructor:

    void drawGrid() {
    
       
        for (int i=1; width < (400);i++){
            width= (400)/10 * i;
          lineItemPtr = c1->addLine(width,0,width,400 );
          lineItemPtr->setVisible(true);
          this->update();
        }
    }
    
    joeQJ 1 Reply Last reply
    0
    • N newQter

      QGraphicsView, QGraphicsscene,addLine

      Hi, I am new to Qt and I wanted to draw some grid lines in the scene in the constructor as a guide for the user to click and draw shapes.

        c1 = new QGraphicsScene(0,0,400,400,this); 
      
          c1->setSceneRect(0,0,400,400); 
          cv1= new QGraphicsView(c1,this);
      

      Given that both my scene and view are bound by rect 400,400, I want to draw say 10 lines as guide/grid on the scene. It seems if I take c1->height() and c1->wdith(), I can addLines in the scene. But, when I change the size of my application window, the lines do not readjust in cv1. Any easy way to accomplish this?

      Here is the drawGrid routine that is called from the constructor:

      void drawGrid() {
      
         
          for (int i=1; width < (400);i++){
              width= (400)/10 * i;
            lineItemPtr = c1->addLine(width,0,width,400 );
            lineItemPtr->setVisible(true);
            this->update();
          }
      }
      
      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

      @newQter hi,friend,welcome.

      do you want to readjust line's position value when the window reset the size?

      if yes. you should reimplement QWidget::resizeEvent function, and to adjust scene size and line's position value.

      you should know when window size changed, the scene in QGraphicsView not to change it's size. and the line's position value also not to change.

      Just do it!

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved