Results 1 to 8 of 8

Thread: treewidget and a message system

  1. #1
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default treewidget and a message system

    hi,

    i want to implement a message system where the message formats are stored in a treewidget. i have created the treewidget and the items with the designer. the structure is as the following:

    message group1
    - message type 11
    - message type 12
    - message type 13
    message group2
    - message type 21
    - message type 22

    when i choose a message from the widget and click `new message` i want to open a dialog box related to the message type.

    my problem is that, in the designer, i cannot set an object name for te treewidgetitem's and the only way i have seen is to compare the treewidgetitem's name when the message type is selected and open the dialog box.

    is there any other way to identify the items selected in the treewidget ?

    sami

  2. #2
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: treewidget and a message system

    Hi,
    i would do it this way:
    create items programatically by

    QTreeWidgetItem *item = new QTreeWidgetItem();
    treeWidget->addTopLevelItem (item);

    and adde them to some additional map

    QMap<QTreeWidgetItem *, msgType> map;
    map[item] = type;
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  3. #3
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: treewidget and a message system

    if i create the items without using the designer, it would be a problem for me, because there are lots of messages and there will be a lot of change in the message list. i don't want to edit the code manually everytime -if possible-.

  4. #4
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: treewidget and a message system

    I'm not sure if i understood your problem.
    You want to associate treeWidgetItems with message types without coding?
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  5. #5
    Join Date
    May 2008
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: treewidget and a message system

    Yes, or any suggestion to carry out the work with another easy way.

    As you may know in windows forms, the tree nodes can be given an object name so that the object can be identified. Is there such a feature for the Qt designer.

    If that would not be possible, sure, I will construct the tree by coding.

  6. #6
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: treewidget and a message system

    Only QObjects(objects of classes that inherits QObject) can be named by setObjectName.

    QTreeWidgetItem is not a QObject, so

    i think you'll have to code it.

    If you don't want to maintain additional code for it, consider reading massages types from kind of text file or xml.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  7. The following user says thank you to mchara for this useful post:

    alisami (16th July 2008)

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: treewidget and a message system

    Notice that QTreeWidgetItems have a built-in support for "types". Alternatively you can use QTreeWidgetItem::setData() with Qt::UserRole to store arbitrary identifier data to each item.
    J-P Nurmi

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: treewidget and a message system

    Quote Originally Posted by alisami View Post
    my problem is that, in the designer, i cannot set an object name for te treewidgetitem's and the only way i have seen is to compare the treewidgetitem's name when the message type is selected and open the dialog box.

    is there any other way to identify the items selected in the treewidget ?
    Each item has an index associated with it, namely a row number, column number and the index of a parent. For instance message type 13 would have an index of "row 2, parent with row 0" or in code:

    Qt Code:
    1. QModelIndex index = tree->currentIndex();
    2. int row = index.row();
    3. int parentrow = index.parent().row();
    4. if(index.parent().isValid()){
    5. switch(parentrow){
    6. case 0: if(row==0) handle_type_11(); else if(row==1) handle_type_12(); else ...
    7. ...
    8. }
    9. } else {
    10. // group clicked
    11. switch(row){
    12. case 0: handle_group_1(); break;
    13. case 1: handle_group_2(); break;
    14. //...
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

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.