Results 1 to 5 of 5

Thread: QStyledItemDelegate : too small to see contents

  1. #1
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QStyledItemDelegate : too small to see contents

    QStyledItemDelegate does a nice job and renders the item using the correct size of the items contents. But when I start editing then the spinbox decoration hides the contents. I’d like to change this behavior so that the content is always visible.(see image 1)

    I subclassed QStyledItemDelegate::updateEditorGeometry to change the width of the editor
    Qt Code:
    1. QSize ExtraSize= QSize(option.rect.width()+ option.decorationSize.width(),option.rect.height());
    2.  
    3. QRect ExtraRect = option.rect;
    4. ExtraRect.setSize(ExtraSize);
    5. editor->setGeometry(ExtraRect);
    To copy to clipboard, switch view to plain text mode 
    But this doesn’t give the expected results. When debugging I see that decorationSize remains the same, even when using larger fonts.
    With QFont fff("Arial",12);

    debugging output : option.decorationSize.width() 16
    (see image 2)



    With QFont fff("Arial",32);

    debugging output : option.decorationSize.width() 16
    (see image 3)


    QUESTION : Can anyone tell me which approach I should use to get the correct size of the decoration?
    Or should I make a custom style instead of using delegates?
    Attached Images Attached Images

  2. #2
    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: QStyledItemDelegate : too small to see contents

    I would put the question differently - what is the effect you want to obtain and what is the reason for wanting to have this effect?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyledItemDelegate : too small to see contents

    Hi Wysota,

    What I want : When I use a QTableView and edit an item the spinbox decoration doesn't hide the content of the time cell. As I understand, this is the default behaviour. Tell me if I'm wrong. I would prefer to have the content always visible, editing or not.

    I tested the different text sizes on windows 7 (100%, 125% and 150%) without hardcoding it with setfont in my program. In that case my code gives what I want : a spinbox on the right of the cell frame and minimal use of space.(see image)

    Conclusion : option.decorationSize.width() adapts to the font size of the Operating system and not to the font size i choose manually in my code with setFont.

    You can see the default editing and my result in the attached image.
    default_result.png

    Cheers Everall

    PS : if somebody wants an example I can send the complete code.

  4. #4
    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: QStyledItemDelegate : too small to see contents

    There is no such thing as "spinbox decoration". The "decoration" of an item is an icon that has nothing to do with the widget performing the role of an editor for an item.

    I'm not sure I understand what the problem is - you mean you want the cell to become wider because as it is now it doesn't fit the whole time format when in edit mode, correct? If so, then you have to return a larger size hint for your item as it is the editor that adjusts to the cell size, not the other way round. You should be able to do that by emitting QAbstractItemDelegate::sizeHintChanged() from the delegate when the editor is created and later return a larger size hint when the view asks the delegate for it.
    Last edited by wysota; 9th December 2010 at 18:35.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Everall (9th December 2010)

  6. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QStyledItemDelegate : too small to see contents

    Hi Wysota,

    You're right : obviously decoration is something else than what I thought. But it gives a result that suits me. So the luck was on my side.


    Nevertheless, I prefer to program as QT is intended to be used, so I will have a look into your approach.

    Thanks for your insight and the sizeHintChanged() tip.

    Everall

Similar Threads

  1. QStyledItemDelegate and editor pointer
    By Nero in forum Qt Programming
    Replies: 10
    Last Post: 20th September 2010, 18:42
  2. QStandardItem, QStyledItemDelegate, and QWebView
    By enlightened_j in forum Newbie
    Replies: 1
    Last Post: 16th August 2010, 08:44
  3. QStyledItemDelegate with custom QWidget editor
    By stefanadelbert in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2010, 23:19
  4. Question about subclassing QStyledItemDelegate
    By dpimka in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2009, 17:09
  5. Setting Format in a QStyledItemDelegate
    By Airswoop1 in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2009, 22:01

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.