Results 1 to 11 of 11

Thread: Scroll View for Canvas

  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 Scroll View for Canvas

    Hi,

    I have created a Canvas....
    Now when i set image for it, it goes beyond its size.. I would like to set up a scroll view for it so that the user can scroll and view the entire image even if it is greater than the canvas size...
    How do i do that...

    Kapil

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scroll View for Canvas

    Are you using Q3Canvas ?

  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: Scroll View for Canvas

    Quote Originally Posted by munna
    Are you using Q3Canvas ?
    yes.. i am using Q3Canvas and to set the view, Q3CanvasView..

    Kapil

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scroll View for Canvas

    use resizeContents(int width ,int height) to set the size of the Q3CanvasView.

  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: Scroll View for Canvas

    Quote Originally Posted by munna
    use resizeContents(int width ,int height) to set the size of the Q3CanvasView.
    Hi,

    resizeContents() would resize the canvas view size to that of the image... but i dont need that.. i explicitly want to add a scroll area to it so that the canvas size remains same and the image can be viewed by moving the scroll bar up-down and right-left..

    Kapil

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scroll View for Canvas

    Quote Originally Posted by kapil
    i explicitly want to add a scroll area to it so that the canvas size remains same and the image can be viewed by moving the scroll bar up-down and right-left..
    Q3CanvasView inherits Q3ScrollView which means that the scrollbars will automatically come if contents size is greater than the viewable area.

  7. #7
    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: Scroll View for Canvas

    Quote Originally Posted by munna
    Q3CanvasView inherits Q3ScrollView which means that the scrollbars will automatically come if contents size is greater than the viewable area.
    Yeaps,

    It does give the scroll bar if the area goes greater than the canvas...
    one more doubt...
    Now i will not know the size of the imgae which is getting loaded..
    So can it resize the CanvasView dynamically by extracting the size of the image and then calling the resizeContents function with those values...

    Kapil

  8. #8
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scroll View for Canvas

    I dont think it can do that. You have to somehow find the size of your canvas and dynamically change the size.

    use size() of Q3Canvas to find the size

    Cheers
    Last edited by munna; 25th March 2006 at 06:57.

  9. The following user says thank you to munna for this useful post:

    Kapil (25th March 2006)

  10. #9
    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: Scroll View for Canvas

    Quote Originally Posted by munna
    I dont think it can do that. You have to somehow find the size of your canvas and dynamically change the size.

    use size() of Q3Canvas to find the size

    Cheers
    hi,

    Thanks a lot...

    i tried that.. i extracted the size of the image and then was able to resize it and it happened... but it is giving improper view...
    the scroll bars comes and it resets the entire window to the size of the image but when i move the scroll bars up and down, they get disappeared... though the functionality of scrollbar is happening but they are not visible...

    why does this happens...

  11. #10
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Scroll View for Canvas

    can i see the code where you are doing this?

  12. #11
    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: Scroll View for Canvas

    Quote Originally Posted by munna
    can i see the code where you are doing this?
    Here is the file:

    Its the open() function which does the functioning.

    Qt Code:
    1. #include "imagezoomer.h"
    2. #include <QtGui>
    3. #include <qdir.h>
    4. #include <QColor>
    5.  
    6. ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin): mwin(_mwin)
    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. canvas = new Q3Canvas(500,500);
    15. canview = new Q3CanvasView(frame);
    16. canview->setCanvas(canvas);
    17. canvas->setBackgroundColor(Qt::black);
    18.  
    19. resize(500, 400);
    20. connect(mwin->actionOpen, SIGNAL(activated()), this, SLOT(open()));
    21.  
    22. }
    23. ImageZoomer::~ImageZoomer()
    24. {
    25. }
    26.  
    27. void ImageZoomer::open()
    28. {
    29. int x,y;
    30. QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::currentPath());
    31.  
    32. if (!filename.isEmpty())
    33. {
    34. QImage image(filename);
    35. if (image.isNull())
    36. {
    37. QMessageBox::information(this, tr("Image Zoomer"),tr("Cannot load %1.").arg(filename));
    38. return;
    39. }
    40. canvas->setBackgroundPixmap(QPixmap::fromImage(image));
    41. scalefactor = 1.0;
    42.  
    43. x = image.width();
    44. y = image.height();
    45.  
    46. canview->resizeContents(x,y);
    47.  
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Scene vs. multiple views
    By lni in forum Qt Programming
    Replies: 16
    Last Post: 19th July 2022, 01:47
  2. World View Zooming factor
    By Pharell in forum General Programming
    Replies: 0
    Last Post: 6th November 2008, 13:04
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. Automatic scroll in graphics view
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 14:07
  5. QScrollArea's Scroll Bars
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 19th September 2006, 13:27

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.