Results 1 to 6 of 6

Thread: Graphics View

  1. #1
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Graphics View

    This code is to match a text int in a block and draw a rectangle at a given position. That is working correctly for one variable but i want when two variables are there in a program then two rectangles will draw.
    For Example :
    int a,b;
    then i want two rectangles will appear (one rectangle for variable a and another for variable b) in graphics view
    Can someone help me?

    if(cursor.block().text().contains("int",Qt::CaseIn sensitive))
    {
    scene.addRect(100,0,90,90,QPen(Qt::black),QBrush(Q t::darkBlue));
    ui->graphicsView->setScene(&scene);

    }

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graphics View

    If you want one rectangle, you call addRect() onces.
    If you want two rectangles, you call addRect() twice. With different coordinates or size if you want them to visually distinguishable.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Graphics View

    Sir for one program this solution is fine but not for bulk of programs. I want if one variable then one rectangle will show, if two variables then two rectangles will show , if three variables three rectangles will show and so on.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Graphics View

    I want if one variable then one rectangle will show, if two variables then two rectangles will show , if three variables three rectangles will show and so on.
    Then draw your rectangles in a loop...

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Graphics View

    Quote Originally Posted by parulkalra14 View Post
    Sir for one program this solution is fine but not for bulk of programs. I want if one variable then one rectangle will show, if two variables then two rectangles will show , if three variables three rectangles will show and so on.
    You will be surprised to read this, but in order to get three rectangles, addRect() needs to be called three times!

    If we assume the laws of induction apply, we can derive that in order to get N rectangles, you'll need to call addRect() N times.

    Cheers,
    _

  6. #6
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Graphics View

    ok..sorry sir for the wrong one..but thanku so much.....

Similar Threads

  1. Cannot open gif in Graphics View
    By alok9871 in forum Newbie
    Replies: 4
    Last Post: 31st December 2012, 07:35
  2. graphics view slow
    By dognzhe in forum Qt Programming
    Replies: 16
    Last Post: 11th May 2009, 17:36
  3. Graphics View Presentation
    By Brandybuck in forum The GraphicsView Framework
    Replies: 0
    Last Post: 29th May 2008, 01:44
  4. Graphics View or Paint ?
    By igor in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2007, 13:21
  5. which is better QCanvas or graphics view?
    By neomax in forum General Discussion
    Replies: 1
    Last Post: 23rd November 2006, 15:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.