Results 1 to 5 of 5

Thread: QScrollArea problem positioning a QWidget inside

  1. #1
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QScrollArea problem positioning a QWidget inside

    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

    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QScrollArea>
    4.  
    5. int main( int argc, char **argv )
    6. {
    7. QApplication a( argc, argv );
    8.  
    9. QMainWindow *mw = new QMainWindow();
    10.  
    11. QScrollArea *sa = new QScrollArea( mw );
    12. sa->setPalette( QPalette( QColor(41,141,40) ) );
    13.  
    14. QWidget *qw = new QWidget( sa );
    15. qw->setPalette( QPalette( QColor(41,161,90) ) );
    16. qw->resize(100,100);
    17. qw->move(80,80);
    18.  
    19. //qw->setGeometry(80,80,100,100);
    20.  
    21. sa->setWidget(qw);
    22.  
    23. mw->setCentralWidget( sa );
    24. mw->show();
    25.  
    26. return a.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea problem positioning a QWidget inside

    Quote Originally Posted by Spectator
    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()

  3. #3
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea problem positioning a QWidget inside

    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.
    Last edited by Spectator; 18th February 2006 at 22:52.

  4. #4
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea problem positioning a QWidget inside

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea problem positioning a QWidget inside

    Quote Originally Posted by Mad Max
    try to use method setFixedSize()
    Try moving the widget after you call setWidget().
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 00:45
  2. Replies: 2
    Last Post: 8th October 2006, 21:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.