Qt事件过滤器

2015-05-12  来源:本站原创  分类:软件工程  人气:896 

事件过滤器比较强大

bool FormSearch::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == this->lineEdit)
    {
        if(event->type() == QEvent::FocusIn)
            this->clearText();
        if(event->type() == QEvent::MouseButtonDblClick)
            this->clearText();
        QKeyEvent *e = static_cast<QKeyEvent*>(event);
        if(e->key() == Qt::Key_Space && (e->modifiers() & Qt::ShiftModifier))
            this->clearText();
    }
    return QWidget::eventFilter(obj,event);
}

过滤器,是针对某个特定的控件,来定义行为。包括键盘,鼠标移入移出等行为。

QEvent下的如FocusIn是由众多的小事件构成的。

还可以针对某一个特定的事件,就是吧event转换成QKeyEvent或者是QMouseEvent类指针。如果是多键组合而成。那么就是类似上方代码。

最后在把事件分发出去。

然后选择控件去installEventFilter(QObject *obj); obj这个指针,会在自身使用的时候转过来引用eventFilter函数。

enter不是回车键哦,return才是。

每个控件包含一个列表,总是先去调用列表中得过滤器,然后再进行自己得处理。所以如果直接返回true,那么这个控件基本上就是不会产生事件了,甚至自身得绘图等事件都不会有。

最先到达子部件,一步步往上传得。

事件系统:

相关文章
  • Qt事件过滤器 2015-05-12

    事件过滤器比较强大 bool FormSearch::eventFilter(QObject *obj, QEvent *event) { if (obj == this->lineEdit) { if(event->type() == QEvent::FocusIn) this->clearText(); if(event->type() == QEvent::MouseButtonDblClick) this->clearText(); QKeyEvent *e = st

  • Qt Model/View 学习笔记 (七) 2014-01-23

    清源游民 [email protected] Delegate 类 概念 与MVC模式不同,model/view结构没有用于与用户交互的完全独立的组件.一般来讲, view负责把数据展示给用户,也处理用户的输入.为了获得更多的灵性性,交互通过delegagte执行.它既提供输入功能又负责渲染view中的每个数据项. 控制delegates的标准接口在QAbstractItemDelegate类中定义.Delegates通过实现paint()和sizeHint()以达到渲染内容的目的.然而,简单的

  • Qt 中的多线程(二) 2015-05-03

    可重入与线程安全 在Qt文档中,术语"可重入"与"线程安全"被用来说明一个函数如何用于多线程程序.假如一个类的任何函数在此类的多个不同的实例上,可以被多个线程同时调用,那么这个类被称为是"可重入"的.假如不同的线程作用在同一个实例上仍可以正常工作,那么称之为"线程安全"的. 大多数c++类天生就是可重入的,因为它们典型地仅仅引用成员数据.任何线程可以在类的一个实例上调用这样的成员函数,只要没有别的线程在同一个实例上调用这个成员

  • Qt中的多线程编程 2010-08-18

    Qt中的多线程编程 级 别: 初级 续欣 ([email protected]), 2004 年 4 月 01 日 Qt 作为一种基于 C++ 的跨平台 GUI 系统,能够提供给用户构造图形用户界面的强大功能.为了满足用户构造复杂图形界面系统的需求,Qt 提供了丰富的多线程编程支持. Qt 作为一种基于 C++ 的跨平台 GUI 系统,能够提供给用户构造图形用户界面的强大功能.为了满足用户构造复杂图形界面系统的需求,Qt 提供了丰富的多线程编程支持.从 2.2 版本开始,Qt 主要从下面三个方

  • qt线程----部分代码片段 2012-11-09

    一.把视频显示到界面的方法 (1)针对qt4的(视频格式为rgb32) v4l_grab_movie(&v4l_dev); unsigned char *pBuffer= v4l_dev.buffer; QImage image(pBuffer,320,240,QImage::Format_RGB32); QPixmap pixmap; pixmap=pixmap.fromImage(image); label->setPixmap(pixmap); label->setFixedSi

  • Qt for Symbian platform to build 2010-03-29

    1. The first erected in the development platform for Symbian-Carbide, here ignored. I'm using Carbide 2.3 version. Ensure normal operation and then perform the following installation Hello world. SDK is best FP1, FP2, S60_5rd. 2.Qt for Symbian instal

  • Introduction to Project 2 QT actual 2010-03-29

    Preceded by a written courseware, including QT to get into some basic analysis, and in culture. On the computer is useless, might as well upload up to share with you

  • Qt programming environment under Windows configuration 2010-03-19

    Eclipse + CDT + MinGW: http://hexlee.javaeye.com/blog/499152 Windows + QT + Eclipse + MinGW tutorial build QT development environment more Keyword: c + + qt eclipse mingw Windows + QT + Eclipse + MinGW detailed tutorial build QT development environme

  • Introduction to Project 2 QT combat 2010-03-14

    A prior written courseware, including some basic analysis of QT entry, and in culture. On the computer useless, might as well post it to share

  • Qt for Symbian development environment configuration 2010-04-30

    Qt development environment for Symbian to support the configuration you must follow these steps to install: (Installation order: 1 -> 2 -> 3 -> 4 -> 5 -> 6) Installation steps: 1. ActivePerl 5.6.1.638 2. Carbide.c + + V2.3 IDE 3. S60 5th Ed

  • Qt is installed in the S60 2010-05-01

    Development Environment: You need a Windows PC. Currently, Windows XP and Windows Vista on the S60 development environment is supported by the best. Check your PC meets the environmental requirements PC . Install IDE: Your machine must have at least

  • Qt and S60 environment settings management is 2010-05-01

    Qt and S60 environment settings management is From Forum Nokia Wiki Platform: S60 3rd Edition FP2, S60 5th Edition Categories: Qt Sub Category: Base / System Keywords: QSettings Outline In this paper, Symbian OS, and Qt comparison between the configu

  • Mandatory use of Qt applications in horizontal or vertical screen screen 2010-05-01

    Mandatory use of Qt applications in horizontal or vertical screen screen From Forum Nokia Wiki Abstract: This article describes how the program in Qt for Symbian mobile phones even when the state changes the level of mandatory use of horizontal or ve

  • Qt Symbian development environment installed 2010-05-01

    Qt for Symbian development environment consists of three parts: the basic tools; Symbian SDK; Qt for Symbian SDK. Please order of installation. Note 1: If the Nokia forum download development tools, you need to you to register a forum account Note 2:

  • Qt and S60 environmental settings management is 2010-05-01

    Qt and S60 environment settings management is From Forum Nokia Wiki Platform: S60 3rd Edition FP2, S60 5th Edition Categories: Qt Sub Category: Base / System Keywords: QSettings Outline In this paper, Symbian OS, and Qt comparison between the configu

  • Qt source code analysis: starting from QObject 2010-06-02

    Originally intended to "Qt way of learning" as something of a similar tutorial, so do not intend to put some content related to the source code on that line among friends. So today the first look at a new start! Progress in this series are not e

  • Qt source code analysis: information hiding (1) 2010-06-02

    If you read Qt's source code, you'll see a bunch of weird macro, for example Q_D, Q_Q. Qt source of our journey to understand the macro from the start with. The following look at a C + + example. class Person { public: Person(){} ~Person(){} string n

  • QT QTableWidget application of some functions 2010-06-03

    setSelectionBehavior(QAbstractItemView::SelectRows); // You can select records setSelectionMode(SingleSelection); // Records can only be single-select, a record highlight setFocusPolicy(Qt::NoFocus); // The mouse does not get focus

  • QT QTableWidgetItem application of some functions 2010-06-03

    QTableWidgetItem *qItem = new QTableWidgetItem( tableLine[i].c_str() ); qItem->setFlags( qItem->flags() & (~Qt::ItemIsEditable & ~Qt::ItemIsSelectable) );// Cannot be edited, not optional ,

  • How to develop Qt applications to add icons 2010-06-03

    First prepare a ICO icons. For example: myappico.ico Write new files with the version which would write a line: IDI_ICON1 ICON DISCARDABLE "myappico.ico" Save renamed myapp.rc and put it together with your icon myappico.ico QT copied to your pro