Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: XML, Highlighting and Model/View

  1. #21
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: XML, Highlighting and Model/View

    Have you tried QAbstractItemModel::data with role=Qt::SizeHintRole?

  2. #22
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML, Highlighting and Model/View

    Not yet... But what shud I return from there ? I dont have font info in data()

    Also how do I do it with QTreeWidget, where I am not using model ? I tried rowHeight and indexRowSizeHint, I put a breakpoint, but the breakpoint was never reached

  3. #23
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: XML, Highlighting and Model/View

    Yes, the fact that stuff like FontRole, SizeHintRole, ForegroundRole etc is 'part' of the model is a bit strange now and then.

    Perhaps QAbstractItemDelegate::sizeHint will help you, then.
    You're rendering in the delegate, so there you should be able to access font info etc.

    And make sure not to set uniformRowHeights on the TreeView (if you want rows of different heights).

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

    Default Re: XML, Highlighting and Model/View

    Quote Originally Posted by aamer4yu View Post
    Not yet... But what shud I return from there ? I dont have font info in data()
    Implement sizeHint() for your delegate. You have the font info there in the option parameter.

  5. #25
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML, Highlighting and Model/View

    Ya i had implemented sizeHint for delegate, but in vain.
    Actually sizeHint is called once initially. So I can set height accordingly. But when I resize the window, treewidget also resize and on this resize I want the row height to increase.

    Which function should I look for ?

    I also tried visualRect, but it doesnt effect too . Also rowHeight and indexRowSizeHint are never called .
    Isnt there any function to update the row height on resize event ?
    Last edited by aamer4yu; 24th June 2008 at 13:07.

  6. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML, Highlighting and Model/View

    The item size should not be dependent on the view size. Make sure uniformRowHeight property of the view is set to false.

  7. #27
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML, Highlighting and Model/View

    It is false. I am getting different row heights.
    I was asking how to set row heights upon resize. Say if window is reduced in width, columnwidth is also reduced. So now I want to resize row height to fit the content acc to new height.

    I am able to set the row height initially once by QItemDelegate::sizeHint() function. I was having 2 errors in it previously -
    I was calculating row height based on -
    Qt Code:
    1. do
    2. {
    3. line++;
    4. elided = fontMetrics.elidedText(textToRender,Qt::ElideNone,width-2);
    5. charsRendered += elided.length();
    6. textToRender = text.mid(charsRendered);
    7. }while(!textToRender.isEmpty());
    8. height = height*line;
    To copy to clipboard, switch view to plain text mode 
    Problem was with Qt::ElideNone. I was getting the original text and the line count was always 1 Is elidedText() supposed to return the original text if mode is Qt::ElideNone ??.

    Second problem was with width = optio.rect.width(); inside sizeHint() function.
    I found that in QTreeView::indexRowSizeHint() function, width is set to -1 for some optimization. Hence I was not getting the proper column width . I set the width manually and now I get the line numbers correctly.

    So far so good. I can assume my application wont be resized and am taking some default column width.

    Still if someone know how to set row height on resize, let me know.

    Thanks for ur help Caduel and Wysota

  8. #28
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML, Highlighting and Model/View

    I landed in another problem.

    The QItemdelegate::sizeHint() doesnt work same with QTreeWidget and QTreeView.
    In the Simple DOM example, in the QItemdelegate::sizeHint(), I am getting proper font in option parameter. While in QItemdelegate::sizeHint(), delegate set for MyTreeWidget, I dont get the proper font.

    Hence while calculatin row height, I get a difference in these 2 implementations. Why is it so ??

    Also another doubt, if we setWordWrap(true) on QTreeView, isnt it supposed to display text in multiple lines ? One can easily check using Simple DOM model and setting word wrap to true for the treeview.
    Last edited by aamer4yu; 25th June 2008 at 10:13.

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

    Default Re: XML, Highlighting and Model/View

    Quote Originally Posted by aamer4yu View Post
    Still if someone know how to set row height on resize, let me know.
    There is a sizeHintChanged() signal in QAbstractItemDelegate. You can apply an event filter to the view so that you know when its size changes and emit that signal from within the delegate and the view should re-ask the delegate for new sizes then. I think it's worth to try...

    Quote Originally Posted by aamer4yu View Post
    The QItemdelegate::sizeHint() doesnt work same with QTreeWidget and QTreeView.
    Sure it does

    In the Simple DOM example, in the QItemdelegate::sizeHint(), I am getting proper font in option parameter. While in QItemdelegate::sizeHint(), delegate set for MyTreeWidget, I dont get the proper font.
    What do you consider a "proper" font?

    Also another doubt, if we setWordWrap(true) on QTreeView, isnt it supposed to display text in multiple lines ?
    Yes, but this works only on word-breaks, I think. I did see it work, at least.

  10. #30
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML, Highlighting and Model/View

    What do you consider a "proper" font?
    By proper font I mean the font I set on the TreeWidget or the TreeView.

    The QItemdelegate::sizeHint() doesnt work same with QTreeWidget and QTreeView.
    Yes, it doesnt for me. Well I meant the overrided sizeHint. What I did was I overrided sizeHint of my delegate. Say MyDelegate::sizeHint. I am using this delegate in 2 programs.

    One MyTreeWidget/MyTreeWidgetItem (P1), and other modified version of Simple DOM(P2) Model. In P1 I set MyTreeWidget->setFont(myFont) after creating the tree. In P2 I did the same.
    Now in P1 , in MyDelegate::sizeHint, I get the font from option.font as system default - MS Shell Dialog2(something like that ) . and in P2 , in MyDelegate::sizeHint, for option.font I get font as myFont. This is what I mean that sizeHint doesnt work same in both cases


    As for Word wrap, did u try setting word wrap to true for QTreeView in simple DOM model example and shrink the window width ??

    For sizeHintChanged() , I will surely try.
    But its gonna fail. In MyDelegate::sizeHint() function, i get option.rect.width() as -1. This is set in QTreeView::indexRowSizeHint() function for some hack
    You can verify from the QTreeView::indexRowSizeHint() function.

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
  •  
Qt is a trademark of The Qt Company.