Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can QObject use type to filter ?
Forum Updated to NodeBB v4.3 + New Features

Can QObject use type to filter ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 498 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    QObject->type() == QWidget::QPushButton

    bool TitleBar::eventFilter(QObject *obj, QEvent *event)
    {
        if ( obj->type() == QWidget::QPushButton && event->type() == QEvent::MouseMove ) {
            return true;    // filter
        } else {
            return false;
        }
        // pass the event on to the parent class
        return QWidget::eventFilter(obj, event);
    }
    

    https://github.com/sonichy

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      Hi,
      You can look at the class name::

      obj->metaObject()->className();
      

      return the class Name "QPushButton"

      or using a dynamic cast

      QPushButton* button=qobject_cast<QPushButton*>(obj)
      

      button == nullptr if obj is not a QPushButton

      Be aware that subclass like QCommandLinkButton, in that case, are QPushButton too.

      sonichyS 1 Reply Last reply
      6
      • M mpergand

        Hi,
        You can look at the class name::

        obj->metaObject()->className();
        

        return the class Name "QPushButton"

        or using a dynamic cast

        QPushButton* button=qobject_cast<QPushButton*>(obj)
        

        button == nullptr if obj is not a QPushButton

        Be aware that subclass like QCommandLinkButton, in that case, are QPushButton too.

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by sonichy
        #3

        @mpergand Thank you !

        if ( QString(obj->metaObject()->className()) == "QPushButton" && event->type() == QEvent::MouseMove ) {
            ...
        }
        

        https://github.com/sonichy

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved