[self solved]Text lose highlight



  • Hi guys,

    I customized my treeview that inherited from QTreeview. I wanna drag and drop work and reimplement mousepressevent,releaseevent and moveevent. everything works very well. but when I click on items in my treeview, text loses highlight. welcome any advices. thanks a lot



  • First advice: show relevant code.



  • my Code:

    @
    MyTreeView::MyTreeView(QWidget *parent) :
    QTreeView(parent)
    {
    }

    MyTreeView::~MyTreeView()
    {
    }

    void MyTreeView::mousePressEvent(QMouseEvent *event)
    {
    //to do my logic
    QTreeView::mousePressEvent(event);
    }

    void MyTreeView::mouseMoveEvent(QMouseEvent *event)
    {
    //to do my logic
    QTreeView::mouseMoveEvent(event);
    }

    void MyTreeView::mouseReleaseEvent(QMouseEvent *event)
    {
    //to do my logic
    QTreeView::mouseReleaseEvent(event);
    }
    @



  • this problem has been fixed,just add one line:

    @
    void MyTreeView::mouseReleaseEvent(QMouseEvent *event)
    {
    //to do my logic
    QTreeView::mouseReleaseEvent(event);
    QModelIndex currentIndex = this->indexAt(event->pos());
    if(currentIndex.isValid())
    {
    this->setCurrentIndex(currentIndex);
    }
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.