Results 1 to 8 of 8

Thread: Styling Model/View items based on their ItemDataRole properties

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2012
    Location
    Wrocław, Poland
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Styling Model/View items based on their ItemDataRole properties

    Quote Originally Posted by wysota View Post
    It's not that much more work. I don't know how complex your styling is but it shouldn't be that hard to either do the same in a delegate or integrate the two approaches. For example implementing border-image in C++ is up to 9 lines of code.
    So is there a way to access stylesheet data from within QStyledItemDelegate? The painting/measuring methods of QStyle do access it. But I didn't see any way to do it myself neither using QStyle nor QStyleOptionViewItem.

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

    Default Re: Styling Model/View items based on their ItemDataRole properties

    Quote Originally Posted by Adam Badura View Post
    So is there a way to access stylesheet data from within QStyledItemDelegate?
    No, what sense would it make? QStyledItemDelegate will respect your stylesheet by itself if you remember to call the base class implementation in your subclass.
    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
    Aug 2012
    Location
    Wrocław, Poland
    Posts
    25
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Styling Model/View items based on their ItemDataRole properties

    Quote Originally Posted by wysota View Post
    No, what sense would it make? QStyledItemDelegate will respect your stylesheet by itself if you remember to call the base class implementation in your subclass.
    That way I could set up some styles which I would then query for myself (in item delegate) and use them in painting operation. Now I cannot (for model/view items) - or better to say I'm very limited in my options. If I would like to use border-image for fancier (stretched) background in normal, alternate and selected modes then its all fine. But if my items have another "mode" like for example "erroneous" with red background then how should I proceed? Since as for now I can see just one option: throw away the stylesheet and embed everything in item delegate.

    Actually this is what I was advised to do by my co-workers. But I found it hard to believe that it cannot be done with stylesheets as main "style" source.

    (The border-image example is not just a sample. QStyleOptionViewItem don't seem to provide means to set/overwrite border-image. It only allow to set background brush. Which will be then cheerfully overpainted with the border-image that comes from stylesheet...)

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

    Default Re: Styling Model/View items based on their ItemDataRole properties

    Quote Originally Posted by Adam Badura View Post
    That way I could set up some styles which I would then query for myself (in item delegate) and use them in painting operation.
    Well, you can query whatever you want. The stylesheet is available in the stylesheet property of the widget, its parent, etc. But there is no cascading and no parsing. You have to do everything manually. Of course you can store a stylesheet for each item separately in the model and then parse it and do whatever you want with it.

    Now I cannot (for model/view items) - or better to say I'm very limited in my options. If I would like to use border-image for fancier (stretched) background in normal, alternate and selected modes then its all fine. But if my items have another "mode" like for example "erroneous" with red background then how should I proceed? Since as for now I can see just one option: throw away the stylesheet and embed everything in item delegate.
    I already told you that implementing border-image in C++ is 9 lines of code (or less).

    Actually this is what I was advised to do by my co-workers. But I found it hard to believe that it cannot be done with stylesheets as main "style" source.
    If all you want from style sheets is image-border, then drop the stylesheet and paint the image in the delegate the way you want it.
    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.


Similar Threads

  1. Replies: 4
    Last Post: 18th April 2012, 18:11
  2. From item based widgets to model/view
    By timom in forum Qt Programming
    Replies: 2
    Last Post: 22nd September 2011, 07:35
  3. Model-view: Display items in different ways
    By taboom in forum Qt Programming
    Replies: 3
    Last Post: 13th August 2007, 19:05
  4. Replies: 4
    Last Post: 18th May 2006, 17:48
  5. Sorting Tree items based on database properties
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2006, 19:44

Tags for this Thread

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.