Results 1 to 14 of 14

Thread: Subclassing QScrollView

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Subclassing QScrollView

    Hi

    I am creating a widget ImageView by subclassing QScrollView and passing the file-path of Pixmap in its constructor. Then I reimplement QScrollView's drawContents functions in my class:
    Qt Code:
    1. void ImageView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ) {
    2. p->drawPixmap( 0, 0, *_pixmap );
    3. }
    To copy to clipboard, switch view to plain text mode 

    But I am not getting the full functionality and also its not showing scroll-bars, while they are set to auto.
    And also I am not getting the full understanding of the subclassing QScrollView, i.e what should the proper way...

    thanks & regards
    sumsin

  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: Subclassing QScrollView

    Have you see your picture?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QScrollView

    ya, I can see the Picture and it is always at top-left of viewport.

  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: Subclassing QScrollView

    try resizeContents(yourpictureWidth,yourpictureHeight)

  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QScrollView

    should I reimplement resizecontents() ?
    And is my code of drawcontents sufficient?

    I also attaching my ImageView.
    Attached Images Attached Images
    • File Type: png 1.png (33.2 KB, 11 views)
    Last edited by sumsin; 16th March 2006 at 14:03.

  6. #6
    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: Subclassing QScrollView

    Quote Originally Posted by sumsin
    ya, I can see the Picture and it is always at top-left of viewport.
    its ok becouse you draw it there
    a life without programming is like an empty bottle

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

    Default Re: Subclassing QScrollView

    no need to reimplement it.

    Just call the slot (not inside drawContents but somewhere before drawContents gets called).

    I think the code inside drawContents will suffice.

  8. #8
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QScrollView

    but drawContents called automatically.
    plz guide me...

  9. #9
    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: Subclassing QScrollView

    Quote Originally Posted by sumsin
    should I reimplement resizecontents() ?
    And is my code of drawcontents sufficient?

    I also attaching my ImageView.
    why?

    what actually you want to do ?
    a life without programming is like an empty bottle

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Subclassing QScrollView

    How about setting the image on a QLabel and placing the label inside the scroll view?

  11. #11
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QScrollView

    I actually want that at startup my widget opens in a default size and if the size of the image is larger than the size of viewport then it should show the scrollbars.
    And when I resize the widget manually it should manage itself so that every time the image try to be in center.

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

    Default Re: Subclassing QScrollView

    but drawContents called automatically.
    yes. So call resizeContents in function where you get your pixmap.

  13. #13
    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: Subclassing QScrollView

    Quote Originally Posted by munna
    try resizeContents(yourpictureWidth,yourpictureHeight)
    it must help you!
    a life without programming is like an empty bottle

  14. #14
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Subclassing QScrollView

    thanks
    my scroll-bars now appear.
    One thing when I send the arguments in resizecontents as mypicwidth and mypicheight, but it not seem that the widget size match these arguments.
    Widget size is lesser.
    And how i put the image in center.
    Should I apply some transformation in drawcontents function but I am not exactly understanding the means of clipx, clipy, clipw and cliph.

Similar Threads

  1. subclassing QWidget
    By BeS in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2009, 20:38
  2. Subclassing QAbstractItemView
    By psih128 in forum Qt Programming
    Replies: 4
    Last Post: 13th October 2008, 07:32
  3. QScrollView size policy?
    By Henrikas[MI] in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2006, 10:52
  4. Problem with QTreeWidget after subclassing
    By steve918 in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2006, 18:51
  5. How to find size provided by QScrollView
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2006, 09:26

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.