PDA

View Full Version : Subclassing QScrollView



sumsin
16th March 2006, 13:43
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:


void ImageView::drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ) {
p->drawPixmap( 0, 0, *_pixmap );
}


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

zlatko
16th March 2006, 13:47
Have you see your picture?

sumsin
16th March 2006, 13:51
ya, I can see the Picture and it is always at top-left of viewport.

munna
16th March 2006, 13:57
try resizeContents(yourpictureWidth,yourpictureHeight)

sumsin
16th March 2006, 13:59
should I reimplement resizecontents() ?
And is my code of drawcontents sufficient?

I also attaching my ImageView.

zlatko
16th March 2006, 14:01
ya, I can see the Picture and it is always at top-left of viewport.

its ok becouse you draw it there;)

munna
16th March 2006, 14:03
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.

sumsin
16th March 2006, 14:03
but drawContents called automatically.
plz guide me...:confused:

zlatko
16th March 2006, 14:04
should I reimplement resizecontents() ?
And is my code of drawcontents sufficient?

I also attaching my ImageView.

why?

what actually you want to do ?

jpn
16th March 2006, 14:06
How about setting the image on a QLabel and placing the label inside the scroll view?

sumsin
16th March 2006, 14:09
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.

munna
16th March 2006, 14:10
but drawContents called automatically.

yes. So call resizeContents in function where you get your pixmap.

zlatko
16th March 2006, 14:12
try resizeContents(yourpictureWidth,yourpictureHeight)

it must help you!

sumsin
16th March 2006, 14:20
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.