Results 1 to 3 of 3

Thread: QScrollArea ?

  1. #1
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QScrollArea ?

    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:
    Qt Code:
    1. #ifndef TESTWIDGET_H
    2. #define TESTWIDGET_H
    3.  
    4. #include <QtGui>
    5.  
    6. class TestWidget : public QWidget{
    7. Q_OBJECT
    8. public:
    9. TestWidget(QWidget * parent=0, const char * name=0, Qt::WFlags f=0);
    10. ~TestWidget();
    11.  
    12. QPushButton *bZoom;
    13.  
    14. public slots:
    15. void slotShrink();
    16. };
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    Implementation:
    Qt Code:
    1. #include "myWidget.h"
    2.  
    3. TestWidget::TestWidget(QWidget * parent, const char * name, Qt::WFlags f):QWidget(parent, f)
    4. {
    5. bZoom = new QPushButton(this);
    6. bZoom->setText("Shrink");
    7. connect(bZoom, SIGNAL(clicked()), this, SLOT(slotShrink()));
    8. }
    9.  
    10. void TestWidget::slotShrink()
    11. {
    12. this->resize(this->width()-5, this->height()-5);
    13. }
    14.  
    15. TestWidget::~TestWidget()
    16. {
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    Main:
    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QScrollArea>
    4. #include "myWidget.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QMainWindow *mw = new QMainWindow();
    11. mw->resize(400,400);
    12.  
    13. QScrollArea *sa = new QScrollArea( mw );
    14. sa->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    15. sa->setBackgroundRole(QPalette::Dark);
    16.  
    17. QWidget *qw = new TestWidget( sa );
    18. QObject::connect(qw, SIGNAL(clicked()), &a, SLOT(slotShrink()));
    19. qw->setPalette( QPalette( QColor(0,0,255) ) );
    20. qw->resize(200,200);
    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 

    What is the problem, can anyone help me?

    Thanks.
    Last edited by whitefurrows; 27th July 2007 at 22:57.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

  3. The following user says thank you to jpn for this useful post:

    whitefurrows (27th July 2007)

  4. #3
    Join Date
    May 2006
    Posts
    108
    Thanks
    35
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: QScrollArea ?

    Thank you for the assistance

Similar Threads

  1. QScrollArea and resizing
    By rarefluid in forum Qt Programming
    Replies: 8
    Last Post: 22nd July 2007, 15:18
  2. Replies: 2
    Last Post: 8th October 2006, 21:14
  3. Replies: 7
    Last Post: 20th September 2006, 15:45
  4. is there any signal for QScrollArea?
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2006, 08:12
  5. QScrollArea problem positioning a QWidget inside
    By Spectator in forum Qt Programming
    Replies: 4
    Last Post: 20th February 2006, 23:59

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.