Hello,

I have a problem with Qt's QTreeWidget. Selection does not work correctly for cells containing a custom display widget. When the widget is clicked for the first time, the row is selected and then never again, the selected row is still rendered as if it was selected. When I collapse the tree's root, it works again (for a single time). The example below contains two columns, I want the selection for the first one (containing the custom widget) to work just like the second one (not having a custom widget). Do you have an idea what's causing this? My fruitless solution attempt is found below the following example (I chose a button for simplicity, but my actual widget is a different one):

Qt Code:
  1. int main(int argn, char** argv)
  2. {
  3. QApplication a(argn, argv);
  4.  
  5. tree.resize(300, 500);
  6. tree.setColumnCount(2);
  7. tree.show();
  8.  
  9. for(unsigned int i = 0; i < 2; i++)
  10. {
  11. QTreeWidgetItem *root = new QTreeWidgetItem(&tree);
  12. root->setFlags(root->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
  13. tree.setItemWidget(root, 0, new QPushButton("Root"));
  14. root->setText(1, "A");
  15.  
  16. child->setFlags(child->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
  17. child->setText(1, "B");
  18. root->addChild(child);
  19. tree.setItemWidget(child, 0, new QPushButton("Child"));
  20. }
  21.  
  22. return a.exec();
  23. }
To copy to clipboard, switch view to plain text mode 

I assumed, that mouse events are not propagated correctly. I tried to solve it with a custom widget (set uing setItemWidget), which ignores mousePressEvent. The event is then indeed passed to the tree, but no selection happens:

Qt Code:
  1. class Button : public QPushButton
  2. {
  3. public:
  4. Button(const QString& text) : QPushButton(text) {}
  5. ~Button() {}
  6.  
  7. void mousePressEvent(QMouseEvent *event)
  8. {
  9. QPushButton::mousePressEvent(event);
  10. cout << "Button pressed" << endl;
  11. event->ignore();
  12. }
  13.  
  14. protected:
  15. };
To copy to clipboard, switch view to plain text mode 

Thank you for your help!