Results 1 to 4 of 4

Thread: Determining class of icon in Draggable Icons example

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Determining class of icon in Draggable Icons example

    In the Draggable Icons examples, there is a mouse press event with this code:

    Qt Code:
    1. void DragWidget::mousePressEvent(QMouseEvent *event)
    2. {
    3. QLabel *child = static_cast<QLabel*>(childAt(event->pos()));
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

    How would I change it so that I can determine what class the object childAt(event->pos()) is? I looked at the QWidget documentation, and I couldn't find a function similar to something like getClass() or getObjectType(). Any help would be appreciated.

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Determining class of icon in Draggable Icons example

    I don't find anything either... what about setting a objectName (QObject property) each time you create a QWidget, or maybe setAccessibleDescription with the type?

  3. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    518
    Thanks
    13
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Determining class of icon in Draggable Icons example

    Hi, if you have a limited number of possible classes, you can use QObject::qobject_cast for this. It returns zero if childAt(event->pos()) is not of the type you tried to cast it to.

    Ginsengelf

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Determining class of icon in Draggable Icons example

    please do not an set object name.

    Ask the childAt for its metaObject. It should answer all your question. There is className, inherits and so in the metaObject.
    It's nice to be important but it's more important to be nice.

Similar Threads

  1. Displaying the Icons name,while moving mouse on Icon
    By yuvaraj.yadav in forum Qt Programming
    Replies: 3
    Last Post: 22nd April 2009, 20:17
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.