PDA

View Full Version : Qscrollarea does not scroll



kabanek
29th September 2010, 13:40
I'm trying to use scrollarea, but I don't get scrollbars.

In my constructor I have

ui->setupUi(this);
Canvas = new JCanvas;
ui->scrollArea->setWidget(Canvas);
Canvas->setGeometry(0, 0, 0, 0);
where JCanvas is my implementation of QLabel.

Next, I load a picture and then


QPixmap _image;
_image.load(_fileName);
_image = _image.scaledToWidth(_getSize.PictureWidth);
Canvas->setPixmap(&_image);
//...
qDebug()<<ui->scrollArea->geometry();
qDebug()<<_image.size();

in the output for example I got

QRect(11,47 1498x1262)
QSize(1500, 1220)
so size of the pictura is bigger than my qscrollarea.

Here is a screenshot
5250

Lykurg
29th September 2010, 14:30
Since your scroll area is defined in an ui-file: Are you sure, you set the right scroll bar policies? (See verticalScrollBarPolicy and horizontalScrollBarPolicy)

kabanek
29th September 2010, 22:21
I set ScrollBarAsNeeded in both

wysota
29th September 2010, 22:55
What does your Canvas implementation look like? Does it have a layout? If not, did you reimplement sizeHint()?

kabanek
29th September 2010, 23:08
no and no...

part of JCanvas.h


class JCanvas : public QLabel
{
public:
JCanvas();
void paintEvent(QPaintEvent *);
bool ShowHelpingLines;
void setPixmap(QPixmap *p);
void mouseMoveEvent(QMouseEvent *ev);
void mousePressEvent(QMouseEvent *ev);
void setLabels(QLabel *labelX, QLabel *labelY);

QStringList cutImages(QString dir);

helpingLines HelpingLines;
QVector<JSquare> Squares;
void clearSquares();

private:
QPen Pen;
QPen PenCut;
int MouseX, MouseY;
QPixmap Pixmap;
QLabel *LabelX, *LabelY;
};

wysota
30th September 2010, 00:55
You need to implement sizeHint() properly for your widget to inform its environment about its preferred/required size. QLabel already does that but if you change its behaviour it is likely to return wrong values for what you are doing.

kabanek
3rd October 2010, 16:56
thanks.

Unfortunately, I don't know how the implementation should look like...

wysota
3rd October 2010, 20:10
You are the only one who may know it. Only you know what it does and how it does it. We don't.

ChrisW67
4th October 2010, 03:51
At a guess your size hint should be the same as the size of the image you load into the JCanvas. Implement QWidget::sizeHint() in your JCanvas and return that size as a starting point. You may also want to try setting QSizePolicy::Fixed on the JCanvas.