Using methods from private classes
-
Hi.
I need to check whenever user press on the string or folders sign on QTreeView.
I saw qt source of mousePressEvent:void QTreeView::mousePressEvent(QMouseEvent *event) { Q_D(QTreeView); bool handled = false; if (style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonPress) handled = d->expandOrCollapseItemAtPos(event->pos()); if (!handled && d->itemDecorationAt(event->pos()) == -1) QAbstractItemView::mousePressEvent(event); }
There are using of the expandOrCollapseItemAtPos(QPos *) and itemDecorationAt(QPos *) methods. These methods located in the QTreeViewPrivate class.
Can I use these methods? Is it legal?
Do I need to reimplement QTreeViewPrivate class to use these methods?Thank you.
-
Can I use these methods? Is it legal?
Yes you can. You need to include
widgets-private
inQT
variable in qmake to do so.Remember, though, that these methods are called private for a reason - normally users do not need to use them. Also, Qt does not offer any source / binary compatibility promises for private classes.
Are you sure you can't achieve your goals without private classes?
-
@mrjj
My task is to drag items from QTreeView to another widget.
But when I try to drag item this item makes selected. I need to drag items without selection them.
So I want to reimplement mousePressEvent.
But I still need to collapse/expand items, so if I reimplement mousePressEvent I need to see which area of the item (string or sign) user pressed.