Re: Scroll View for Canvas
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
Re: Scroll View for Canvas
use resizeContents(int width ,int height) to set the size of the Q3CanvasView.
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
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.
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
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
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...
Re: Scroll View for Canvas
can i see the code where you are doing this?
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.
Code:
#include "imagezoomer.h"
#include <QtGui>
#include <qdir.h>
#include <QColor>
ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin): mwin(_mwin)
{
frame
= new QFrame(mwin
->centralwidget
);
frame
->setGeometry
(QRect(60,
70,
591,
571));
frame
->setFrameShape
(QFrame::StyledPanel);
frame
->setFrameShadow
(QFrame::Plain);
canvas = new Q3Canvas(500,500);
canview = new Q3CanvasView(frame);
canview->setCanvas(canvas);
canvas->setBackgroundColor(Qt::black);
resize(500, 400);
connect(mwin->actionOpen, SIGNAL(activated()), this, SLOT(open()));
}
ImageZoomer::~ImageZoomer()
{
}
void ImageZoomer::open()
{
int x,y;
if (!filename.isEmpty())
{
if (image.isNull())
{
QMessageBox::information(this, tr
("Image Zoomer"),tr
("Cannot load %1.").
arg(filename
));
return;
}
canvas
->setBackgroundPixmap
(QPixmap::fromImage(image
));
scalefactor = 1.0;
x = image.width();
y = image.height();
canview->resizeContents(x,y);
}
}