[SOLVED]How to delete an item from the treeview by droping an item to pushbutton or to an group box
-
@Ratzz said:
But i do not want the user to allow listview items to dragged to pushbutton/groupbox
So why can you not check there ?
also
http://doc.qt.io/qt-5/qtreewidget.html#dropMimeData
Seems to be when something is dropped on Tree and im confused what it has to do with the
Groupbox ? -
@mrjj
Since the groupbox is deletes item as you suggested it also deletes listview items when dragged. -
@Ratzz
And the DragGBox do have
void dragEnterEvent(QDragEnterEvent* event) {
event->acceptProposedAction();
}So why cant you just check that sender if the accepted one and then acccept or if not then
reject the drop? -
@mrjj
dragEnterEvent
shoud be used for main class? -
@mrjj said:
For the DropGroupBox class.
I assume you use that one? -
@mrjj
yes i have used this one.
Since its different class how to pull the sender to it?
can you just drop me some piece of code. -
@mrjj
Not it does not allow even the treeview items to drop -
STOP
sender() not working for events it seems.
So cannot work.
So its a no go. -
@mrjj
ok fine.. what next?! -
@Ratzz
you can use
QWidget * QDropEvent::source() const -
@mrjj
this way?void dragEnterEvent(QDragEnterEvent* event) { QWidget * theone= dynamic_cast<QWidget*>(event->source()); if( theone == NULL ) { event->acceptProposedAction(); } }
-
@Ratzz
almost but must be the type you want to allow
QTreeView * theone= dynamic_cast<QTreeView*>(event->source());
if( theone != NULL )
{
event->acceptProposedAction();
}so it says if it IS a Treeview then say ok
For other types, it should not allow then. (red sign)
I hope :) -
@mrjj
yes its working fine :)
i should implement for Pushbutton also . -
@Ratzz
Super :) -
@mrjj
when i click delete button i doui->label->setText(QString::number(parent->rowCount()));
which gives me count of the number of rows. But if i drag the row will be deleted but count is not getting updated. how to update it ?
Should it be done onGroupDropBox
?? -
@Ratzz
GroupBox would not know about parent.
The Tree should update when the It is removed.But then you drag, do you call the buttons on_click so the
ui->label->setText(QString::number(parent->rowCount()))
is executed ?
The groupBox example does not call anything as the Tree removes the item it self so
I assume that is why you dont see Count Changes. -
Hi
you could also cheat a bit and use a timer.QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateMinorFrameCount()));
timer->start(1000); -
@mrjj
cheating works fine :)