PDA

View Full Version : QScrollArea ?



whitefurrows
27th July 2007, 21:52
Hello,

i have center a QWidget in a QScrollArea, but when i resize the QWidget move that to the left corner on top.

Header file:

#ifndef TESTWIDGET_H
#define TESTWIDGET_H

#include <QtGui>

class TestWidget : public QWidget{
Q_OBJECT
public:
TestWidget(QWidget * parent=0, const char * name=0, Qt::WFlags f=0);
~TestWidget();

QPushButton *bZoom;

public slots:
void slotShrink();
};

#endif

Implementation:

#include "myWidget.h"

TestWidget::TestWidget(QWidget * parent, const char * name, Qt::WFlags f):QWidget(parent, f)
{
bZoom = new QPushButton(this);
bZoom->setText("Shrink");
connect(bZoom, SIGNAL(clicked()), this, SLOT(slotShrink()));
}

void TestWidget::slotShrink()
{
this->resize(this->width()-5, this->height()-5);
}

TestWidget::~TestWidget()
{

}

Main:

#include <QApplication>
#include <QMainWindow>
#include <QScrollArea>
#include "myWidget.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QMainWindow *mw = new QMainWindow();
mw->resize(400,400);

QScrollArea *sa = new QScrollArea( mw );
sa->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
sa->setBackgroundRole(QPalette::Dark);

QWidget *qw = new TestWidget( sa );
QObject::connect(qw, SIGNAL(clicked()), &a, SLOT(slotShrink()));
qw->setPalette( QPalette( QColor(0,0,255) ) );
qw->resize(200,200);
sa->setWidget(qw);

mw->setCentralWidget( sa );
mw->show();

return a.exec();
}

What is the problem, can anyone help me?

Thanks.

jpn
27th July 2007, 22:03
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=136824

whitefurrows
27th July 2007, 22:15
Thank you for the assistance