Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. void MyTableHeader::headerSectionClicked(int section_index, int click_pos)
  2. {
  3. int section_size = sectionSize(0); // All sections in a header are equally sized
  4. int section_center = (section_size * (section_index+ 1)) - (section_size / 2); // Center of the clicked section
  5.  
  6. if (section_index>= 0)// if mouse is over an item
  7. {
  8. if (orientation() == Qt::Horizontal)
  9. {
  10. QPoint x_pos = QPoint(click_pos, 0);
  11. int mapped_offset = viewport()->mapFrom(this, x_pos).x();
  12.  
  13. if (mapped_offset != -1)
  14. {
  15. // If the click was to the right of the center, iterate on the index
  16. if (mapped_offset >= section_center)
  17. {
  18. in_index++;
  19. }
  20. }
  21. }
  22. else
  23. {
  24. // Same thing for the Y-dimension
  25. }
  26. }
  27.  
  28. // Neat stuff after this
  29. }
  30.  
  31. // If the click was to the right of the center, iterate on the index
  32. if (mapped_offset >= section_center)
  33. {
  34. in_index++;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement