Results 1 to 4 of 4

Thread: QTreeWidget Horizontal header double click event???

  1. #1
    Join Date
    Jan 2011
    Location
    Sri Lanaka
    Posts
    64
    Thanks
    39
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default QTreeWidget Horizontal header double click event???

    Hello,

    any1 know how to catch "QTreeWidget Horizontal header double click event"?
    this is my QtreeWidget, what i wont is when i double click on horizontal header item, Tree should check all the item in that selected column ..
    any ideas ??

    .H fie
    Qt Code:
    1. ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17. void initTree();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21.  
    22. private slots:
    23.  
    24. };
    25.  
    26. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    .CPP file
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QTreeWidget>
    4. #include <QTreeWidgetItem>
    5. #include "MyStyle.h"
    6. #include <QMultiMap>
    7.  
    8. QTreeWidget* pTree;
    9. QList<QTreeWidgetItem*> lstWidgets;
    10. QList<QTreeWidgetItem*> lstSubItems;
    11.  
    12.  
    13. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    14. {
    15. ui->setupUi(this);
    16. pTree = NULL;
    17. initTree();
    18. QSize size(540,870);
    19. this->resize(size);
    20. this->setMinimumSize(size);
    21. this->setMaximumSize(size);
    22. ui->gridLayout->addWidget(pTree);
    23. }
    24.  
    25. MainWindow::~MainWindow()
    26. {
    27. delete ui;
    28. }
    29.  
    30. void MainWindow::initTree()
    31. {
    32. pTree = new QTreeWidget(this);
    33. pTree->setGeometry(10,10,520,850);
    34. pTree->setMaximumSize(520,850);
    35. pTree->show();
    36.  
    37. QStringList lstheadrs;
    38. lstheadrs.append(" \n \n \n \n \n \n ");
    39. lstheadrs.append("1");
    40. lstheadrs.append("2");
    41. lstheadrs.append("3");
    42. lstheadrs.append("4");
    43. lstheadrs.append("5");
    44. lstheadrs.append("6");
    45. lstheadrs.append("7");
    46. lstheadrs.append("8");
    47. lstheadrs.append("9");
    48. lstheadrs.append("10");
    49. lstheadrs.append("11");
    50. lstheadrs.append("12");
    51. pTree->setHeaderLabels(lstheadrs);
    52. //------SET COLUMN WIDTH---------------
    53. pTree->setColumnWidth(0,190);
    54. for(int i = 1; i<=12; i++)
    55. {
    56. pTree->setColumnWidth(i,25);
    57. }
    58. MyStyle *headerStyl = new MyStyle(this->style());
    59. pTree->setStyle(headerStyl);
    60.  
    61. //==========================================================================================================//
    62. QTreeWidgetItem *Node1 = new QTreeWidgetItem(pTree, QStringList(QObject::tr("1")));
    63. Node1->addChild(new QTreeWidgetItem(QStringList(QObject::tr("1.1"))));
    64. Node1->addChild(new QTreeWidgetItem(QStringList(QObject::tr("1.2"))));
    65. Node1->addChild(new QTreeWidgetItem(QStringList(QObject::tr("1.3"))));
    66. pTree->expandItem(Node1);
    67. for(int iChild=0; iChild<Node1->childCount() ; iChild++)
    68. for(int i=1; i<lstheadrs.length(); i++)
    69. Node1->child(iChild)->setCheckState(i,Qt::Unchecked);
    70.  
    71. lstWidgets.append(Node1);
    72. //==========================================================================================================//
    73. QTreeWidgetItem *Node2 = new QTreeWidgetItem(pTree, QStringList(QObject::tr("2")));
    74. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.1"))));
    75. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.2"))));
    76. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.3"))));
    77. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.4"))));
    78. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.5"))));
    79. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.6"))));
    80. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.7"))));
    81. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.8"))));
    82. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.9"))));
    83. Node2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("2.10"))));
    84. pTree->expandItem(Node2);
    85. for(int iChild=0; iChild<Node2->childCount() ; iChild++)
    86. for(int i=1; i<lstheadrs.length(); i++)
    87. Node2->child(iChild)->setCheckState(i,Qt::Unchecked);
    88.  
    89. lstWidgets.append(Node2);
    90. //==========================================================================================================//
    91. QTreeWidgetItem *Node3 = new QTreeWidgetItem(pTree,QStringList(QObject::tr("3")));
    92.  
    93. QTreeWidgetItem *node3sub1 = new QTreeWidgetItem(Node3, QStringList(QObject::tr("3.1")));
    94. node3sub1->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.1.1"))));
    95. node3sub1->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.1.2"))));
    96. node3sub1->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.1.3"))));
    97. Node3->addChild(node3sub1);
    98. for(int iChild=0; iChild<node3sub1->childCount(); iChild++)
    99. for(int i=1; i<lstheadrs.length(); i++)
    100. node3sub1->child(iChild)->setCheckState(i,Qt::Unchecked);
    101.  
    102. QTreeWidgetItem *node3sub2 = new QTreeWidgetItem(Node3, QStringList(QObject::tr("3.2")));
    103. node3sub2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.2.1"))));
    104. node3sub2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.2.2"))));
    105. node3sub2->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.2.3"))));
    106. Node3->addChild(node3sub2);
    107. for(int iChild=0; iChild<node3sub2->childCount(); ++iChild)
    108. for(int i=1; i<lstheadrs.length(); i++)
    109. node3sub2->child(iChild)->setCheckState(i,Qt::Unchecked);
    110.  
    111. QTreeWidgetItem *node3sub3 = new QTreeWidgetItem(Node3, QStringList(QObject::tr("3.3")));
    112. node3sub3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.3.1"))));
    113. node3sub3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.3.2"))));
    114. node3sub3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.3.3"))));
    115. Node3->addChild(node3sub3);
    116. for(int iChild=0; iChild<node3sub3->childCount(); iChild++)
    117. for(int i=1; i<lstheadrs.length(); i++)
    118. node3sub3->child(iChild)->setCheckState(i,Qt::Unchecked);
    119.  
    120.  
    121. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.4"))));
    122. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.5"))));
    123. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.6"))));
    124. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.7"))));
    125. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.8"))));
    126. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.9"))));
    127. Node3->addChild(new QTreeWidgetItem(QStringList(QObject::tr("3.10"))));
    128.  
    129. pTree->expandItem(Node3);
    130. for(int iChild=0; iChild<Node3->childCount() ; iChild++)
    131. for(int i=1; i<lstheadrs.length(); i++)
    132. Node3->child(iChild)->setCheckState(i,Qt::Unchecked);
    133.  
    134. lstWidgets.append(Node3);
    135. lstWidgets.append(node3sub1);
    136. lstWidgets.append(node3sub2);
    137. lstWidgets.append(node3sub3);
    138. //==========================================================================================================//
    139. QTreeWidgetItem *node4 = new QTreeWidgetItem(pTree, QStringList(QObject::tr("4")));
    140. node4->addChild(new QTreeWidgetItem(QStringList(QObject::tr("4.1"))));
    141. node4->addChild(new QTreeWidgetItem(QStringList(QObject::tr("4.2"))));
    142. pTree->expandItem(node4);
    143. for(int iChild=0; iChild<node4->childCount() ; iChild++)
    144. for(int i=1; i<lstheadrs.length(); i++)
    145. node4->child(iChild)->setCheckState(i,Qt::Unchecked);
    146.  
    147. lstWidgets.append(node4);
    148. //==========================================================================================================//
    149. QTreeWidgetItem *node5 = new QTreeWidgetItem(pTree, QStringList(QObject::tr("5")));
    150. node5->addChild(new QTreeWidgetItem(QStringList(QObject::tr("5.1"))));
    151. node5->addChild(new QTreeWidgetItem(QStringList(QObject::tr("5.2"))));
    152. node5->addChild(new QTreeWidgetItem(QStringList(QObject::tr("5.3"))));
    153. node5->addChild(new QTreeWidgetItem(QStringList(QObject::tr("5.4"))));
    154. pTree->expandItem(node5);
    155. for(int iChild=0; iChild<node5->childCount() ; iChild++)
    156. for(int i=1; i<lstheadrs.length(); i++)
    157. node5->child(iChild)->setCheckState(i,Qt::Unchecked);
    158.  
    159. lstWidgets.append(node5);
    160. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2011
    Location
    Sri Lanaka
    Posts
    64
    Thanks
    39
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QTreeWidget Horizontal header double click event???

    hope this does not mean that there is no way to do this.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTreeWidget Horizontal header double click event???

    What's about the signal QHeaderView::sectionDoubleClicked()?

  4. The following user says thank you to Lykurg for this useful post:

    deepal_de (6th June 2011)

  5. #4
    Join Date
    Jan 2011
    Location
    Sri Lanaka
    Posts
    64
    Thanks
    39
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QTreeWidget Horizontal header double click event???

    Thanks
    answer
    Qt Code:
    1. // pTee is the QTreeWidget
    2.  
    3. bConnect = connect( pTree->header(), SIGNAL( sectionDoubleClicked(int) ), this, SLOT( treeHeaderDoubleClick(int) ) );
    4.  
    5. treeHeaderDoubleClick(int)
    6. {
    7. // What ever you wont to do in click this event
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. how to disable double click event on qmainwindow titlebar?
    By banlinhtienphong in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2011, 11:23
  2. Replies: 1
    Last Post: 3rd May 2010, 10:25
  3. can not get mouse double click event for QGraphicsItem
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2009, 21:36
  4. QTreeWidget double click - expand problem
    By stefan in forum Newbie
    Replies: 2
    Last Post: 29th June 2008, 14:24
  5. QTreeWidget double click signal
    By Pinco Pallino in forum Newbie
    Replies: 2
    Last Post: 18th November 2006, 17:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.