Results 1 to 3 of 3

Thread: QComboBox in QTreeWidget

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Unhappy QComboBox in QTreeWidget

    Hi, all.

    I inserted a QComboBox using setItemWidget() in QTreeWidget.

    The issue I am having is when I click on the QComboBox, the list drops down and then immediately closes again, so it is impossible to select an item on the list.

    Thanks in advance for any suggestion.

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox in QTreeWidget

    Could you please show some source code?

  3. #3
    Join Date
    Sep 2009
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QComboBox in QTreeWidget

    Quote Originally Posted by e8johan View Post
    Could you please show some source code?
    Qt Code:
    1. // TRW_OHEDIT is a Object name of QTreeWidget.
    2. // m_name is a string.
    3. void BS_OHEdit::SetTreeViewOfEdit2()
    4. {
    5. QTreeWidgetItem *name = new QTreeWidgetItem(TRW_OHEDIT);
    6. QTreeWidgetItem *byte = new QTreeWidgetItem(name);
    7. QTreeWidgetItem *format = new QTreeWidgetItem(name);
    8. QTreeWidgetItem *bit1_4 = new QTreeWidgetItem(name);
    9. QTreeWidgetItem *req = new QTreeWidgetItem(name);
    10. QTreeWidgetItem *bit5_8 = new QTreeWidgetItem(name);
    11. QTreeWidgetItem *channel = new QTreeWidgetItem(name);
    12.  
    13. cb_edit1 = new QComboBox(this); // format
    14. cb_edit2 = new QComboBox(this); // request
    15. cb_edit3 = new QComboBox(this); // channel
    16.  
    17. cb_edit1->setFixedSize(70, 35);
    18. cb_edit1->addItems(QStringList() << "Encode" << "Binary");
    19. cb_edit2->setFixedHeight(35);
    20. cb_edit2->addItems(MakeNameOfK1("req"));
    21. cb_edit3->setFixedSize(200, 35);
    22. cb_edit3->addItems(MakeNameOfK1("channel"));
    23.  
    24. le_edit1 = new QLineEdit(this); // bits 1-4
    25. le_edit2 = new QLineEdit(this); // bits 5-8
    26.  
    27. le_edit1->setFixedSize(50, 35);
    28. le_edit1->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    29. le_edit1->setInputMask("BBBB;0");
    30. le_edit1->setEnabled(false);
    31. le_edit2->setFixedSize(50, 35);
    32. le_edit2->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    33. le_edit2->setInputMask("BBBB;0");
    34. le_edit2->setEnabled(false);
    35.  
    36. name->setText(0, m_name);
    37. byte->setText(0, "Byte"); byte->setText(1, NameOfByte(m_name));
    38. format->setText(0, "Format"); TRW_OHEDIT->setItemWidget(format, 1, cb_edit1);
    39. bit1_4->setText(0, "Bits 1-4"); TRW_OHEDIT->setItemWidget(bit1_4, 1, le_edit1);
    40. req->setText(0, "Request"); TRW_OHEDIT->setItemWidget(req, 1, cb_edit2);
    41. bit5_8->setText(0, "Bits 5-8"); TRW_OHEDIT->setItemWidget(bit5_8, 1, le_edit2);
    42. channel->setText(0, "Channel"); TRW_OHEDIT->setItemWidget(channel, 1, cb_edit3);
    43.  
    44. connect(cb_edit1, SIGNAL(currentIndexChanged(QString)), this, SLOT(cb_format_edit2_currentIndexChanged(QString)));
    45. connect(cb_edit2, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_req_edit2_currentIndexChanged(int)));
    46. connect(cb_edit3, SIGNAL(currentIndexChanged(int)), this, SLOT(cb_channel_edit2_currentIndexChanged(int)));
    47. connect(le_edit1, SIGNAL(textChanged(QString)), this, SLOT(le_bit14_edit2_textChanged()));
    48. connect(le_edit2, SIGNAL(textChanged(QString)), this, SLOT(le_bit58_edit2_textChanged()));
    49.  
    50. TRW_OHEDIT->expandAll();
    51. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your reply.

Similar Threads

  1. Filling QTreeWidget / Using QTreeView
    By stefanborries in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2009, 15:25
  2. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  4. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14
  5. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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.