Hello everybody,
I have problem regarding QtextEdit and scrollView. My target is to make the cursor in TextEdit to be visible whenever I type something in it. The horizontal scrollBars should move accordingly once the cursor in the textEdit is at the end of the visible area of the frame. For this I have defined 3 classes namely

1) class myFrame : public QFrame
A frame which has a QtextEdit in it.

2) class myScroll : public QScrollView
ScrollView for scrolling purpose, which has myFrame in it. myFrame makes use of viewport defined in this class

3) class myWidget : public QMainWindow
A mainWidow which has scrollview

When I just type in the TextEdit, I want the scrollView to move the scrolls accordingly. This basically means I want the cursor in TextEdit to be visible anyTime I type in it.

I have written sample code but is unable to find what is wrong.
//test.h
Qt Code:
  1. #include <qscrollview.h>
  2. #include <qframe.h>
  3. #include <qtextedit.h>
  4. #include <qmainwindow.h>
  5.  
  6. class myFrame : public QFrame
  7. {
  8. Q_OBJECT
  9. public:
  10. myFrame ( QWidget *parent=0, const char *name="myFrame" );
  11. ~myFrame();
  12. QTextEdit* getEditor()
  13. {
  14. return myEditor;
  15. }
  16. public slots:
  17. void slotTextChanged();
  18. private:
  19. QTextEdit* myEditor;
  20. };
  21.  
  22. class myScroll : public QScrollView
  23. {
  24. public:
  25. myScroll ( QWidget *parent=0, const char *name="ScrollChemCanvas" );
  26. ~myScroll();
  27. private:
  28. myFrame* f;
  29. };
  30.  
  31. class myWidget : public QMainWindow
  32. {
  33. public:
  34. myWidget ( QWidget *parent=0, const char *name="myWidget" );
  35. ~myWidget();
  36. private:
  37. myScroll* scroll;
  38. };
To copy to clipboard, switch view to plain text mode 

//test.cpp
Qt Code:
  1. #include "test.h"
  2.  
  3. myWidget::myWidget ( QWidget *parent, const char *name )
  4. :QMainWindow(parent, name)
  5. {
  6. scroll = new myScroll(this);
  7. CHECK_PTR( scroll );
  8. scroll->setFrameStyle( QFrame::Box | QFrame::Raised );
  9. scroll->setMinimumSize( 200, 200 );
  10. setCentralWidget( scroll );
  11. }
  12.  
  13. myWidget::~myWidget()
  14. {
  15.  
  16. }
  17.  
  18. myScroll ::myScroll ( QWidget *parent, const char *name )
  19. :QScrollView(parent, name)
  20. {
  21. f = new myFrame(viewport());
  22. f->setBackgroundColor( Qt::blue );
  23. f->resize( parentWidget()->width(), parentWidget()->height() );
  24. f->getEditor()->resize( f->width(), f->getEditor()->height() );
  25. addChild(f);
  26. addChild(f->getEditor());
  27. f->getEditor()->ensureCursorVisible();
  28. }
  29.  
  30. myScroll::~myScroll()
  31. {
  32.  
  33. }
  34.  
  35. myFrame::myFrame ( QWidget *parent, const char *name )
  36. : QFrame(parent, name)
  37. {
  38. myEditor = new QTextEdit(parentWidget());
  39. connect( myEditor, SIGNAL( textChanged () ), this, SLOT(slotTextChanged()));
  40. }
  41.  
  42. myFrame::~myFrame()
  43. {
  44.  
  45. }
  46.  
  47. void myFrame::slotTextChanged()
  48. {
  49. }
To copy to clipboard, switch view to plain text mode 

//main.cpp
Qt Code:
  1. #include <qapplication.h>
  2. #include "test.h"
  3.  
  4. int main( int argc, char ** argv )
  5. {
  6. QApplication a( argc, argv );
  7. myWidget w;
  8. w.show();
  9. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode 

Help me to fix this problem.

Thanks in advance