Handle QFocusEvent : QFocusEvent « Qt « C++

Home
C++
1.Bitset
2.Class
3.Console
4.Data Structure
5.Data Type
6.Deque
7.Development
8.File
9.Function
10.Generic
11.Language
12.List
13.Map Multimap
14.Overload
15.Pointer
16.Qt
17.Queue Stack
18.Set Multiset
19.STL Algorithms Binary search
20.STL Algorithms Heap
21.STL Algorithms Helper
22.STL Algorithms Iterator
23.STL Algorithms Merge
24.STL Algorithms Min Max
25.STL Algorithms Modifying sequence operations
26.STL Algorithms Non modifying sequence operations
27.STL Algorithms Sorting
28.STL Basics
29.String
30.Valarray
31.Vector
C / ANSI-C
C Tutorial
C++ Tutorial
Visual C++ .NET
C++ » Qt » QFocusEventScreenshots 
Handle QFocusEvent
  
Foundations of Qt Development\Chapter06\eventlister\eventwidget.cpp
/*
 * Copyright (c) 2006-2007, Johan Thelin
 
 * All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 
 *     * Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice,  
 *       this list of conditions and the following disclaimer in the documentation 
 *       and/or other materials provided with the distribution.
 *     * Neither the name of APress nor the names of its contributors 
 *       may be used to endorse or promote products derived from this software 
 *       without specific prior written permission.
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <QCloseEvent>
#include <QContextMenuEvent>
#include <QEvent>
#include <QFocusEvent>
#include <QHideEvent>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QShowEvent>
#include <QWheelEvent>

#include "eventwidget.h"

EventWidget::EventWidgetQWidget *parent : QWidgetparent )
{
}

void EventWidget::closeEventQCloseEvent * event )
{
  emit gotEventtr("closeEvent") );
}

void EventWidget::enterEventQEvent * event )
{
  emit gotEventtr("enterEvent") );
}

void EventWidget::leaveEventQEvent * event )
{
  emit gotEventtr("leaveEvent") );
}

void EventWidget::hideEventQHideEvent * event )
{
  emit gotEventtr("hideEvent") );
}

void EventWidget::showEventQShowEvent * event )
{
  emit gotEventtr("showEvent") );
}

void EventWidget::paintEventQPaintEvent * event )
{
  emit gotEventtr("paintEvent") );
}

void EventWidget::contextMenuEventQContextMenuEvent * event )
{
  emit gotEventtr("contextMenuEvent( x:%1, y:%2, reason:%3 )")
    .arg(event->x())
    .arg(event->y())
    .arg(event->reason()==2?"Other":
         event->reason()==1?"Keyboard":
                            "Mouse") );
}

void EventWidget::focusInEventQFocusEvent * event )
{
  emit gotEventtr("focusInEvent( reason:%1 )")
    .argevent->reason()==0?"MouseFocusReason":
          event->reason()==1?"TabFocusReason":
          event->reason()==2?"BacktabFocusReason":
          event->reason()==3?"ActiveWindowFocusReason":
          event->reason()==4?"PopupFocusReason":
          event->reason()==5?"ShortcutFocusReason":
          event->reason()==6?"MenuBarFocusReason":
                             "OtherFocusReason" ) );
}

void EventWidget::focusOutEventQFocusEvent * event )
{
  emit gotEventtr("focusOutEvent( reason:%1 )")
    .argevent->reason()==0?"MouseFocusReason":
          event->reason()==1?"TabFocusReason":
          event->reason()==2?"BacktabFocusReason":
          event->reason()==3?"ActiveWindowFocusReason":
          event->reason()==4?"PopupFocusReason":
          event->reason()==5?"ShortcutFocusReason":
          event->reason()==6?"MenuBarFocusReason":
                             "OtherFocusReason" ) );
}

void EventWidget::keyPressEventQKeyEvent * event )
{
  emit gotEventtr("keyPressEvent( text:%1, modifiers:%2 )")
    .argevent->text() )
    .argevent->modifiers()==0?tr("NoModifier"):(
         (event->modifiers()&Qt::ShiftModifier      ==0?tr(""):
            tr("ShiftModifier "))+
         (event->modifiers()&Qt::ControlModifier    ==0?tr(""):
            tr("ControlModifier "))+
         (event->modifiers()&Qt::AltModifier        ==0?tr(""):
            tr("AltModifier "))+
         (event->modifiers()&Qt::MetaModifier       ==0?tr(""):
            tr("MetaModifier "))+
         (event->modifiers()&Qt::KeypadModifier     ==0?tr(""):
            tr("KeypadModifier "))+
         (event->modifiers()&Qt::GroupSwitchModifier==0?tr(""):
            tr("GroupSwitchModifier")) ) ) );
}

void EventWidget::keyReleaseEventQKeyEvent * event )
{
  emit gotEventtr("keyReleaseEvent( text:%1, modifiers:%2 )")
    .argevent->text() )
    .argevent->modifiers()==0?tr("NoModifier"):(
         (event->modifiers()&Qt::ShiftModifier      ==0?tr(""):
            tr("ShiftModifier "))+
         (event->modifiers()&Qt::ControlModifier    ==0?tr(""):
            tr("ControlModifier "))+
         (event->modifiers()&Qt::AltModifier        ==0?tr(""):
            tr("AltModifier "))+
         (event->modifiers()&Qt::MetaModifier       ==0?tr(""):
            tr("MetaModifier "))+
         (event->modifiers()&Qt::KeypadModifier     ==0?tr(""):
            tr("KeypadModifier "))+
         (event->modifiers()&Qt::GroupSwitchModifier==0?tr(""):
            tr("GroupSwitchModifier")) ) ) );
}

void EventWidget::mouseDoubleClickEventQMouseEvent * event )
{
  emit gotEventtr("mouseDoubleClickEvent( x:%1, y:%2, button:%3 )")
    .argevent->x() )
    .argevent->y() )
    .argevent->button()==Qt::LeftButton? "LeftButton":
          event->button()==Qt::RightButton?"RightButton":
          event->button()==Qt::MidButton?  "MidButton":
          event->button()==Qt::XButton1?   "XButton1":
                                           "XButton2" ) );
}

void EventWidget::mouseMoveEventQMouseEvent * event )
{
  emit gotEventtr("mouseMoveEvent( x:%1, y:%2, button:%3 )")
    .argevent->x() )
    .argevent->y() )
    .argevent->button()==Qt::LeftButton? "LeftButton":
          event->button()==Qt::RightButton?"RightButton":
          event->button()==Qt::MidButton?  "MidButton":
          event->button()==Qt::XButton1?   "XButton1":
                                           "XButton2" ) );
}

void EventWidget::mousePressEventQMouseEvent * event )
{
  emit gotEventtr("mousePressEvent( x:%1, y:%2, button:%3 )")
    .argevent->x() )
    .argevent->y() )
    .argevent->button()==Qt::LeftButton? "LeftButton":
          event->button()==Qt::RightButton?"RightButton":
          event->button()==Qt::MidButton?  "MidButton":
          event->button()==Qt::XButton1?   "XButton1":
                                           "XButton2" ) );
}

void EventWidget::mouseReleaseEventQMouseEvent * event )
{
  emit gotEventtr("mouseReleaseEvent( x:%1, y:%2, button:%3 )")
    .argevent->x() )
    .argevent->y() )
    .argevent->button()==Qt::LeftButton? "LeftButton":
          event->button()==Qt::RightButton?"RightButton":
          event->button()==Qt::MidButton?  "MidButton":
          event->button()==Qt::XButton1?   "XButton1":
                                           "XButton2" ) );
}

void EventWidget::resizeEventQResizeEvent * event )
{
  emit gotEventtr("resizeEvent( w:%1, h:%2 )")
    .argevent->size().width() )
    .argevent->size().height() ) );
}

void EventWidget::wheelEventQWheelEvent * event )
{
  emit gotEventtr("wheelEvent( x:%1, y:%2, delta:%3, orientation:%4 )")
    .argevent->x() )
    .argevent->y() )
    .argevent->delta() ).argevent->orientation()==1?
      "Horizontal":"Vertical" ) );
}



Foundations of Qt Development\Chapter06\eventlister\eventwidget.h
/*
 * Copyright (c) 2006-2007, Johan Thelin
 
 * All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 
 *     * Redistributions of source code must retain the above copyright notice, 
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice,  
 *       this list of conditions and the following disclaimer in the documentation 
 *       and/or other materials provided with the distribution.
 *     * Neither the name of APress nor the names of its contributors 
 *       may be used to endorse or promote products derived from this software 
 *       without specific prior written permission.
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef EVENTWIDGET_H
#define EVENTWIDGET_H

#include <QWidget>

class QCloseEvent;
class QContextMenuEvent;
class QEvent;
class QFocusEvent;
class QHideEvent;
class QKeyEvent;
class QMouseEvent;
class QPaintEvent;
class QResizeEvent;
class QShowEvent;
class QWheelEvent;

class EventWidget : public QWidget
{
  Q_OBJECT
  
public:
  EventWidgetQWidget *parent = );

signals:
  void gotEventconst QString );

protected:
  void closeEventQCloseEvent * event );
  void contextMenuEventQContextMenuEvent * event );
  void enterEventQEvent * event );
  void focusInEventQFocusEvent * event );
  void focusOutEventQFocusEvent * event );
  void hideEventQHideEvent * event );
  void keyPressEventQKeyEvent * event );
  void keyReleaseEventQKeyEvent * event );
  void leaveEventQEvent * event );
  void mouseDoubleClickEventQMouseEvent * event );
  void mouseMoveEventQMouseEvent * event );
  void mousePressEventQMouseEvent * event );
  void mouseReleaseEventQMouseEvent * event );
  void paintEventQPaintEvent * event );
  void resizeEventQResizeEvent * event );
  void showEventQShowEvent * event );
  void wheelEventQWheelEvent * event );
};

#endif // EVENTWIDGET_H



Foundations of Qt Development\Chapter06\eventlister\main.cpp
/*
 * Copyright (c) 2006-2007, Johan Thelin
 
 * All rights reserved.
 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 
 *     * Redistributions of source code must retain the above copyright notice, 
 *     * Redistributions in binary form must reproduce the above copyright notice,  
 *       this list of conditions and the following disclaimer in the documentation 
 *       and/or other materials provided with the distribution.
 *     * Neither the name of APress nor the names of its contributors 
 *       may be used to endorse or promote products derived from this software 
 *       without specific prior written permission.
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include <QApplication>
#include <QTextEdit>

#include "eventwidget.h"

int mainint argc, char **argv )
{
  QApplication appargc, argv );
  
  QTextEdit log;
  EventWidget widget;
  
  QObject::connect&widget, SIGNAL(gotEvent(QString)), &log, SLOT(append(QString)) );
      
  log.show();
  widget.show();
  
  return app.exec();
}

   
    
  
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.