PDA

View Full Version : QScrollArea problem positioning a QWidget inside



Spectator
17th February 2006, 17:43
i'm trying to move a QWidget which is inside of a QScrollArea but neither setGeometry() nor move() do work. here's a small example. what am i doing wrong here? qw always stays on the top left and doesn't move :(



#include <QApplication>
#include <QMainWindow>
#include <QScrollArea>

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

QMainWindow *mw = new QMainWindow();

QScrollArea *sa = new QScrollArea( mw );
sa->setPalette( QPalette( QColor(41,141,40) ) );

QWidget *qw = new QWidget( sa );
qw->setPalette( QPalette( QColor(41,161,90) ) );
qw->resize(100,100);
qw->move(80,80);

//qw->setGeometry(80,80,100,100);

sa->setWidget(qw);

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

return a.exec();
}

Mad Max
17th February 2006, 18:15
i'm trying to move a QWidget which is inside of a QScrollArea but neither setGeometry() nor move() do work. here's a small example. what am i doing wrong here? qw always stays on the top left and doesn't move :(


try to use method setFixedSize()

Spectator
18th February 2006, 21:47
in which way would that help me? (have no qt environment here at the moment to test it)

i can set the widget's size without problems, but i can't chose where to position it inside of the scrollarea.

resize(100,100) works and makes the widget 100x100. the size part of setGeomety(int x, int y, int w, int h) also works but the positioning part not, same with move, no movement.

Spectator
20th February 2006, 22:02
anyone?

I used a workaround now but i'm still confused why there's no way to move the QWidget inside the QScrollArea.

Workaround: used a QHBoxLayout together with some QSpacerItems to center the QWidget horizontally on the screen. But as I said above, i'm still confused.

Chicken Blood Machine
20th February 2006, 22:59
try to use method setFixedSize()

Try moving the widget after you call setWidget().