Image Component Library (ICL)
ThreadedUpdatableWidget.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/ThreadedUpdatableWidget.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/Macros.h>
34 #include <QWidget>
35 #include <QApplication>
36 #include <QtCore/QEvent>
37 #include <QtCore/QThread>
38 
39 namespace icl{
40  namespace qt{
41 
43 
51  class ThreadedUpdatableWidget : public QWidget{
52  public:
53 
55  ThreadedUpdatableWidget(QWidget *parent = 0): QWidget(parent){}
56 
58 
61  if(QThread::currentThread() == QCoreApplication::instance()->thread()){
62  update();
63  }else{
64  QApplication::postEvent(this,new QEvent(QEvent::User),Qt::HighEventPriority);
65  }
66 
67  }
68 
70  virtual bool event ( QEvent * event ){
72  if(event->type() == QEvent::User){
73  update();
74  return true;
75  }else{
76  return QWidget::event(event);
77  }
78  }
79  };
80 
81  } // namespace qt
82 }
83 
undocument this line if you encounter any issues!
Definition: Any.h:37
void updateFromOtherThread()
call this function to update a widget's UI from an external thread
Definition: ThreadedUpdatableWidget.h:60
virtual bool event(QEvent *event)
automatically called by Qt's event processing mechanism
Definition: ThreadedUpdatableWidget.h:70
#define ICLASSERT_RETURN_VAL(X, VALUE)
Definition: Macros.h:148
ThreadedUpdatableWidget(QWidget *parent=0)
Base constructor.
Definition: ThreadedUpdatableWidget.h:55
Compability class.
Definition: ThreadedUpdatableWidget.h:51