Results 1 to 6 of 6

Thread: To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetItem.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetItem.

    Hi,

    I am working on Qt4.3.4 on my mac . I want to add an item in QTreeWidget , but QTreeWidgetItem should contain two strings - One String is of greater font than the other and other string is in next line and of smaller font, and also how to get the value of the second string. Image file is attached, for the reference. I want to add item in the QTreeWidget in the way it is in the File Attached.

    Thanks,
    Attached Images Attached Images
    Always Believe in Urself
    Merry

  2. #2
    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: To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetI

    You have two possibilities: a) use a custom delegate (recommended option) b) use QTreeWidget::setItemWidget().

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetI

    Thanks for the reply. Can you pls explain it with an example.....how can i use custom delegate.
    Always Believe in Urself
    Merry

  4. #4
    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: To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetI

    A starting point is "Model/View Programming! in the docs. If you have a more specific question, ask again.

  5. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetI

    Yaa actually I had two strings eg. "String1" and "String2" I had inserted these strings in a QTreeWidget

    Qt Code:
    1. QTreeWidget *treeWidget = new QTreeWidget(this);
    2. QTreeWidgetItem *item1 = new QTreeeWidgetItem(treeWidget);
    3. item1->setText(0,"String1");
    4. tem1->setFont(0,font1);
    5. QTreeWidgetItem *item2 = new QTreeeWidgetItem(item1);
    6. item2->setText(0,"String2");
    7. tem1->setFont(0,font2);
    To copy to clipboard, switch view to plain text mode 

    The output is:

    String1
    String2

    String1 is the parent of String2 and treeWidget is parent of String1

    But I want both the strings should be of the same parent, but should be split and with the different fonts. That I had shown in the Attached file.
    Last edited by Lykurg; 23rd September 2010 at 14:56. Reason: missing [code] tags
    Always Believe in Urself
    Merry

  6. #6
    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: To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetI

    Please use the [code] tags next time. And in your code I can't see a custom delegate nor setItemWidget(). So if you don't try what I suggest you, I really can't help you. I won't provide a ready to use solution!

Similar Threads

  1. QTreeWidgetItem
    By bismitapadhy in forum Qt Programming
    Replies: 12
    Last Post: 7th January 2011, 11:48
  2. moving QTreeWidgetItem
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2009, 21:17
  3. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 18:51
  4. QTreeWidgetItem
    By Sarma in forum Qt Programming
    Replies: 1
    Last Post: 6th April 2006, 20:52
  5. QTreeWidgetItem
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 5th March 2006, 16:07

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.