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. Custom QWidgetListItem and casting
Forum Updated to NodeBB v4.3 + New Features

Custom QWidgetListItem and casting

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 994 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    mookie
    wrote on last edited by
    #1

    I have subclassed the QWidgetListItem and im trying to implement the ability of double clicking it and then populating the data into a dialog to give the user the ability to change the properties of the item.

    my problem is that i dont know how to cast the item properly.

    using qobject_cast doesnt seem to work properly.

    one of my problems is admittedly that im still new to c++ coming from c# world.

    so if i have

    @
    class CustomItem: public QListWidgetItem
    {
    }

    but in my qlistwidget i have

    void CustomListWidget::on_CustomListWidget_itemDoubleClicked(QListWidgetItem *item)
    {

    CustomItem* robot=qobject_cast<CustomItem*>(item);

        qDebug()<<"Show Item Dialog";
    

    }
    @

    how can i cast it so i can pass it along?

    [edit: Added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QListWidgetItem is not a QObject thus qobject_cast will fail. In this case, you can use a dynamic_cast.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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