KFramelistItem::KFramelistItem(Q3ListView *parent, Q3ListViewItem *after, KFramelist *framelist, KFramelistRow *row)
: Q3ListViewItem(parent, after)
, showLines_(false)
, lineColor_(Qt::black)
, framelist_(framelist)
, itemData_(nullptr)
, row_(row)
, dragging_(false)
{
} and I want to port this class and rest mentioned to Qt4 what will be better solution QTreeWidgetItem or QListWidgetItem and acnestors as follows QTreeWiegt and QListWidget
Assistant
In Qt3 you are using Q3ListView and Q3ListViewItem. These classes were part of Qt3's item view framework but were deprecated and replaced in Qt4 by the Model/View framework, which introduced classes like QTreeView, QListView along with the associated models (QStandardItemModel, QAbstractItemModel, etc) and item-based convenience classes like QTreeWidget/QTreeWidgetItem and QListWidget/QListWidgetItem.
Your current code context:
You have a class KFramelistItem inheriting from Q3ListViewItem.
Your KFramelistItem is constructed with a parent item or a Q3ListView* (the view itself), plus some custom data.
From the interface and constructor it seems to be a tree-like structure (parent-child item hierarchy), or at least the code allows a hierarchy of items.
When porting to Qt4, you have basically two high-level choices for item-based widgets:
Use QTreeWidget and QTreeWidgetItem
These classes replace Q3ListView and Q3ListViewItem in the item-based API for hierarchical data (trees).
You can subclass QTreeWidgetItem to add additional functionality.
Use QListWidget and QListWidgetItem
These are simpler list classes for flat lists (no parent-child hierarchy).
Only one level of items. If your existing data has parent/child structure you lose it.
You can subclass QListWidgetItem but it's mainly for flat lists.
Which one is better?
If your existing code uses a hierarchical structure (tree) or depends on parent-child relationships between items (and this is typical for Q3ListViewItem because they support trees), QTreeWidget/QTreeWidgetItem is the better and more direct replacement.
If your existing code is basically a flat list with no nested items, then QListWidget/QListWidgetItem may suffice.
From your constructor signatures, you have Q3ListViewItem *parent as a parameter which suggests you are working with a tree.
Additional notes:
Q3ListView allowed columns and children and tree structures.
Q3ListViewItem can be either top-level or child items.
QTreeWidgetItem supports exactly that—items that can have parents and children, along with multiple columns.
Both QTreeWidget and QTreeWidgetItem support easy data handling and item manipulation, and they integrate nicely with Qt4 model/view design.
Recommendation:
Replace Q3ListView with QTreeWidget.
Replace Q3ListViewItem with QTreeWidgetItem.
Subclass QTreeWidgetItem to add your KFramelistItem data and behavior.
Construct your items using QTreeWidgetItem(parentItem) or QTreeWidgetItem(treeWidget) depending if you want a child or top-level item.
This is the cleanest and most straightforward approach in Qt4.