Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, June 2007
Re: QScrollArea - how to access events? - SOLVED


Message 1 in thread

I worked out a very simple solution to this problem - create a sub-class
of QScrollArea that redirects the events to the object contained in the
QScrollArea. 

class NewScroll : public QScrollArea
{
   void keyPressEvent(QKeyEvent *e) 
   {
        QApplication::sendEvent(widget(),e);
   }
   void resizeEvent(QResizeEvent *e) 
   {
        QScrollArea::resizeEvent(e);
        QApplication::sendEvent(widget(),e);
   }
   void moveEvent(QMoveEvent *e) 
   {
        QScrollArea::moveEvent(e);
        QApplication::sendEvent(widget(),e);
   }
   void closeEvent(QCloseEvent *e) 
   {
        QApplication::sendEvent(widget(),e);
        QWidget::closeEvent(e);
   }
   
public:
   NewScroll() {};
};   

I swallow all of the keystrokes in my contained class as PgUp PgDn rt&lft
arrow have specific functions in the contained class. The mouse scrolling still
works.

A bit kludgey, but it works!

DS

>----- Original Message ----
>From: David Scriven <davidwriter@xxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Sent: Thursday, May 24, 2007 11:09:59 AM
>Subject: QScrollArea - how to access events?
>
>I've created a data-image display system that is based on QGLWidget
>which pops up a stand-alone window containing the image. The size
>of the pseudo-image (i.e. derived from the data) is determined after
>the data is read in.
>
>class DataDisplay :  public QGLWidget
>....
>void DataDisplay::Setup(QString FileName)
>{
>   GetData(FileName);
>   resize(nImageXdim,nImageYdim);
>   show();
>}
>which works very nicely. I have a number of event handlers that
>deal with keyboard, mouse, move, resize  and close events.
 >
>I need to deal with the situation where either 1) the image size is 
>greater than the screen size or 2) the image is zoomed to greater
>than the screen size. 
>
>I tried embedding a QScrollArea in my code:
>
>void DataDisplay::Setup(QString FileName)
>{
>    GetData(FileName);
>
>    imageScroll = new QScrollArea();
>    imageScroll->setWidget(this);
>    imageScroll->setBackgroundRole(QPalette::Dark);
>    resize(nImageXdim,nImageYdim);
>    imageScroll->resize(nImageXdim+5,nImageYdim+5);
 >// this last seems to be necessary so that the image frame matches 
 >// the size of the image and only adds a scroll bar when the image
 >// has exceeds the screen size  - is there a better way to do this?
>.........
>and that works, up to a point - but, of course, now all events such as 
>keyboard, move, etc. are sent to the QScrollArea and not to my original
>class - so how to access them? There seems to be a viewportEvent in 
>the base class, but I'm not sure how how to use this.
>
>DS







      Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail at http://mrd.mail.yahoo.com/try_beta?.intl=ca

--
 [ signature omitted ]