I have a simple Qt application that has a mainwindow and a class (TreeView) that inherits QTreeWidget.
I can't seem to enable the mouse events for the treewidget. The mainwindow with toolbar and menubar works fine but I'm not able to click any of my items in the treeWidget.
I have included QMouseEvent in my class and implemented the virtual functions. Here is one for an example:
void TreeView::itemDoubleClicked(QTreeWidgetItem *item, int column)
{
QMessageBox::information(this, "Message", item->text(column));
}
Am I missing something obvious here?
EDIT: My TreeView.h:
#include <vector>
#include <algorithm>
#include <QTreeWidget>
#include <QMouseEvent>
//ObjectCube includes
#include <Hub.h>
#include <TagSet/TagSet.h>
#include <Tag/Tag.h>
#include "tagsettree.h"
#include "tagtree.h"
using namespace ObjectCube;
class TreeView: public QTreeWidget
{
Q_OBJECT
public:
TreeView(QWidget *parent);
void buildTree(Hub *hub);
void buildEachTagSetTree(TagSetTree *parent);
void addHierarchiesToTree(QTreeWidgetItem *parent, TagSet *tagSet);
void itemDoubleClicked (QTreeWidgetItem *item, int column);
};
The Constructor:
TreeView::TreeView(QWidget *parent): QTreeWidget(parent)
{
this->setHeaderLabel("Images");
this->setEnabled(true);
}
EDIT:
I have fixed what @webclectic pointed out but it has not fixed the problem.
Is there a possibility that I have blocked all mouseEvents in the treeWidget? I can iterate through them with the keyboard but the mouse does not work.
EDIT:
I have a main window. That main window has a pointer to a controller class. The controller class owns instances of all the widgets used in the mainwindow, including the TreeWidget. The main window is the parent of the controller as well as all of the widgets inside of it. Code:
//Constructor
MainController::MainController(QWidget *parent, Hub *hub): QWidget(parent)
{
this->hub = hub;
initializeController(parent);
}
void MainController::initializeController(QWidget *main)
{
treeView = new TreeView(main);
glWidget = new GLWidget(main);
listWidget = new ListWidget(main);
rightSide = new QVBoxLayout(main);
treeView->buildTree(hub);
treeView->move(0, 55);
treeView->resize(main->frameGeometry().width() * 0.2, main->frameGeometry().height() *0.91);
glWidget->move(main->frameGeometry().width() * 0.32 ,55);
glWidget->resize(main->frameGeometry().width() * 0.67, main->frameGeometry().height() *0.91);
rightSide->addWidget(listWidget);
rightSide->setGeometry(QRect(QPoint(main->geometry().width() -20 , 55), QPoint(main->geometry().width(),main->geometry().height())));
}
Gísli
QTreeWidget
instead of your class? You can also reimplement the mousePressEvent() or mouseDoubleClickEvent() and add a qDebug message inside them to see what is going on. Try to create a minimal example where the problem is still present, and you will find what is going wrong...