Results 1 to 10 of 10

Thread: Elements out of Range!!

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Elements out of Range!!

    Hi...

    The objects that i have created are going out of the range of the canvas...
    My canvas size is (400,400) -> visible to the user...
    i have set the CanvasView to (1000,1000)..
    Now when i create objects on canvas, only those which fit on the canvas ie whose x,y coordinates are withing canvas zise ie (400,400) are created and rest all are not...
    I cannot increase the size of the Canvas...
    How do i create beyond the Canvas Size and view them with the help of Scroll View..
    Is it possible to create items till the size (1000,1000) and let only (400,400) be visible on the frame...

    Thanking you,
    Kapil

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Elements out of Range!!

    Try use resizeContents ( int w, int h ) for canvas view
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Elements out of Range!!

    Quote Originally Posted by zlatko
    Try use resizeContents ( int w, int h ) for canvas view
    Hi..

    i used that.. But then it adds a Scroll Bar to the Canvas but does not permit me to draw the elements...

    Isn't there a way with which i am able to create a Canvas of large size but only smaller portion of it is shown and rest can be seen with the help of moving scrollbars..

    resizeContents(x,y) is not doing the trick.. I checked with it..

    Kapil

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Elements out of Range!!

    Then post actual part of your code
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Elements out of Range!!

    Quote Originally Posted by zlatko
    Then post actual part of your code
    The code is:

    ImageZoomer.cppThis class sets the Frame wherein i would place the Canvas:
    Qt Code:
    1. #include "imagezoomer.h"
    2. #include <QtGui>
    3. #include <qdir.h>
    4. #include <QColor>
    5.  
    6. ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin, Q3Canvas *pCanvas): mwin(_mwin),m_pCanvas(pCanvas)
    7. {
    8.  
    9. frame = new QFrame(mwin->centralwidget);
    10. frame->setGeometry(QRect(60, 70, 591, 571));
    11. frame->setFrameShape(QFrame::StyledPanel);
    12. frame->setFrameShadow(QFrame::Plain);
    13.  
    14. canmouse = new CanvasMouse(m_pCanvas,frame); //Sends the canvas obj and frame obj to CanvasMouse
    15. }
    16. ImageZoomer::~ImageZoomer()
    17. {
    18. }
    To copy to clipboard, switch view to plain text mode 

    CanvasMouse.cpp: This class would create the canvas, set its size and set the CanvasView for it..

    Qt Code:
    1. #include "canvasmouse.h"
    2.  
    3. CanvasMouse::CanvasMouse(Q3Canvas *pCanvas, QFrame *frame): Q3CanvasView(frame)
    4. {
    5. m_pCanvas = pCanvas;
    6. Q3CanvasView::setCanvas(m_pCanvas);
    7. m_pCanvas->setBackgroundColor(Qt::white);
    8. m_pCanvas->resize(400, 400);
    9. resizeContents(1000,1000);
    10.  
    11. imgdraw = new ImageDraw(m_pCanvas);
    12.  
    13. setDraw = false;
    14. startDraw = false;
    15. }
    16.  
    17. CanvasMouse::~CanvasMouse()
    18. {
    19. }
    To copy to clipboard, switch view to plain text mode 

    ImageDraw.cpp: This class would actually draw the elements on the canvas and then display them... Here is the problem.. only 4 rectangles are being created as they fall out of the range of the Canvas...

    Qt Code:
    1. #include "imagedraw.h"
    2. #include <Q3ValueList>
    3.  
    4. ImageDraw::ImageDraw(Q3Canvas *pCanvas): m_pCanvas(pCanvas)
    5. {
    6. drawLine();
    7. drawRectangle();
    8. }
    9. ImageDraw::~ImageDraw()
    10. {
    11. }
    12. void ImageDraw::drawLine()
    13. {
    14. int i;
    15. int xxPoint = 2,xyPoint = 2,yxPoint = 202,yyPoint = 2;
    16. lineNum = 20;
    17. m_pCanvasLine = new Q3CanvasLine*[lineNum];
    18. for(i=0;i<lineNum;i++)
    19. {
    20. xyPoint = (i+1)*4;
    21. yyPoint = xyPoint;
    22. m_pCanvasLine[i] = new Q3CanvasLine(m_pCanvas);
    23. m_pCanvasLine[i]->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
    24. m_pCanvasLine[i]->show();
    25.  
    26. }
    27.  
    28. for(i=0;i<lineNum;i++)
    29. lineList.append(m_pCanvasLine[i]);
    30.  
    31. }
    32.  
    33. void ImageDraw::drawRectangle()
    34. {
    35. int xPoint = 4, yPoint = 100;
    36. int height = 50, width = 80;
    37. int i;
    38. recNum = 10;
    39. m_pCanvasRectangle = new Q3CanvasRectangle*[recNum];
    40. for(i=0;i<recNum;i++)
    41. {
    42. m_pCanvasRectangle[i] = new Q3CanvasRectangle(xPoint, yPoint, width, height, m_pCanvas);
    43. m_pCanvasRectangle[i]->show();
    44. yPoint += 75;
    45. }
    46. for(i=0;i<recNum;i++)
    47. rectList.append(m_pCanvasRectangle[i]);
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

    Kapil

  6. #6
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Elements out of Range!!

    Hi..

    I checked quite a few docs and examples but none of them are able to give me a clue regarding my doubt....
    what can be the approach to solve it out...

    KApil

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Elements out of Range!!

    You have some strange problem. Resizing the canvas makes the canvas bigger. Which part of it is visible has nothing to do with the canvas itself, only with the canvasview size and its world matrix. What exactly do you want to achieve and why?

  8. #8
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Elements out of Range!!

    Quote Originally Posted by wysota
    You have some strange problem. Resizing the canvas makes the canvas bigger. Which part of it is visible has nothing to do with the canvas itself, only with the canvasview size and its world matrix. What exactly do you want to achieve and why?

    Hi...

    Thats my problem.. resizing it is making it bigger than the size i need... I just need 400 X 400 to be seen in the window and the actual canvas to be 1000 X 1000...

    Using canvasview's resizeContents() method, i culdnt get the soln... The problem with it is that it does not reduce the canvas size... if the view's size is greater than the canvas size then the scrollbars are added...

    Now when i keep view bigger and canvas smaller then the elements are just created on the canvas's size and thus not all are created... the moment i increase it, it goes out of the window...

    thats the problem..

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Elements out of Range!!

    Qt Code:
    1. QCanvas *c;
    2. QCanvasView *cv;
    3. //...
    4.  
    5. c->resize(1000,1000);
    6. cv->setFixedSize(400,400);
    To copy to clipboard, switch view to plain text mode 

    This will display a bit less than 400x400 (because of the scrollbars).

  10. The following user says thank you to wysota for this useful post:

    Kapil (3rd April 2006)

  11. #10
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Elements out of Range!!

    Hi wysota..

    Thanks a lot for your help..

    Its working out now...

    Kapil

Similar Threads

  1. QWTdial inverted range
    By jmsbc in forum Qwt
    Replies: 1
    Last Post: 12th January 2009, 21:21
  2. accessing table elements in Qt
    By awanish_jmi in forum Newbie
    Replies: 5
    Last Post: 28th July 2008, 12:51
  3. Replies: 3
    Last Post: 12th June 2008, 11:59
  4. Replies: 2
    Last Post: 20th September 2007, 19:37
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 12:48

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.