Results 1 to 6 of 6

Thread: listview + shader

  1. #1
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default listview + shader

    I need to merge two programs from qt examples
    1) expandingdelegates (listview example)
    2) QML + OpenGL shader program

    Each cell of listview must contain a shader program:
    951af324cd56.jpg

    List model:
    Qt Code:
    1. ListModel {
    2. ListElement {
    3. title: "Pancakes"
    4. picture: "content/pics/pancakes.jpg"
    5. ingredients: "<html><ul><li> 1 cup (150g) self-raising flour<li> 1 tbs caster sugar<li> 3/4 cup (185ml) milk<li> 1 egg</ul></html>"
    6. method: "<html><ol><li> Sift flour and sugar together into a bowl. Add a pinch of salt.</ol></html>"
    7. }
    8. ListElement {
    9. title: "Fruit Salad"
    10. picture: "content/pics/fruit-salad.jpg"
    11. ingredients: "* Seasonal Fruit"
    12. method: "* Chop fruit and place in a bowl."
    13. }
    14. ListElement {
    15. ...
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    shader program:
    Qt Code:
    1. Squircle {
    2. SequentialAnimation on t {
    3. NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
    4. NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
    5. loops: Animation.Infinite
    6. running: true
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    When I add Squircle, it always appears in the background of the program

  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: listview + shader

    Quote Originally Posted by kadet.89 View Post
    When I add Squircle, it always appears in the background of the program
    That's the whole point of the example. Instead, what you want to use is something called ShaderEffect.
    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
    Jul 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: listview + shader

    But I create the texture for the shader program in QGLWidget. How can I pass the coordinates of the polygon and texture in ShaderEffect ? Or how can I bind ShaderEffect in QGLWidget as QGLShaderProgram?

  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: listview + shader

    If you have a texture then just use Image as your element. There is no need for a shader effect then. However I would say that's a very odd use-case to create a texture in QGLWidget and then use it in QtQuick scene. Why don't you create the texture directly in the scene (e.g. using an FBO).
    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. #5
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: listview + shader

    Qt Code:
    1. ListModel {
    2.  
    3. ListElement {
    4. }
    5.  
    6.  
    7. ListElement {}
    8. ListElement {}
    9. ListElement {}
    10. ListElement {}
    11. ListElement {}
    12. ListElement {}
    13. ListElement {}
    14. ListElement {}
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Rectangle {
    2. id: page
    3. width: 400; height: 70*9
    4. color: "black"
    5.  
    6. property color col: "lightsteelblue"
    7. gradient: Gradient {
    8. GradientStop { position: 0.0; color: Qt.tint(root.col, "#20FFFFFF") }
    9. GradientStop { position: 0.1; color: Qt.tint(root.col, "#20AAAAAA") }
    10. GradientStop { position: 0.9; color: Qt.tint(root.col, "#20666666") }
    11. GradientStop { position: 1.0; color: Qt.tint(root.col, "#20000000") }
    12. }
    13.  
    14.  
    15. function saturate(x) {
    16. return Math.min(Math.max(x, 0), 1)
    17. }
    18.  
    19. function sliderToColor(x) {
    20. return Qt.rgba(saturate(Math.max(2 - 6 * x, 6 * x - 4)),
    21. saturate(Math.min(6 * x, 4 - 6 * x)),
    22. saturate(Math.min(6 * x - 2, 6 - 6 * x)))
    23. }
    24.  
    25.  
    26.  
    27. Component {
    28. id: recipeDelegate
    29.  
    30. Item {
    31. id: recipe
    32. property string cc: "green"
    33.  
    34. property real detailsOpacity : 0
    35. width: listView.width
    36. height: 70
    37.  
    38. MouseArea {
    39. anchors.fill: parent
    40. onClicked: recipe.state = 'Details';
    41. }
    42.  
    43. ShaderEffectSource {
    44. id: theSource
    45. sourceItem: theItem
    46. hideSource: true
    47. Image {
    48. id: theItem
    49. width: 311
    50. height: 65
    51. source: "content/img.png"
    52. }
    53. }
    54. ShaderEffect {
    55. x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2
    56. property variant source: theSource
    57. fragmentShader:
    58. "uniform sampler2D source;" +
    59. "varying highp vec2 qt_TexCoord0;" +
    60. "void main() {" +
    61. " gl_FragColor = texture2D(source, qt_TexCoord0);" +
    62. " gl_FragColor.r = 0.5;" +
    63. "}"
    64. }
    65. Rectangle {
    66. id: background
    67. x: 2; y: 2; width: parent.width - x*2; height: parent.height - y*2
    68. color: "#00000000"
    69. border.color: "orange"
    70. radius: 5
    71. }
    72.  
    73.  
    74. // A button to close the detailed view, i.e. set the state back to default ('').
    75. TextButton {
    76. y: 10
    77. anchors { right: background.right; rightMargin: 10 }
    78. opacity: recipe.detailsOpacity
    79. text: "Close"
    80.  
    81. onClicked: recipe.state = '';
    82. }
    83.  
    84. states: State {
    85. name: "Details"
    86.  
    87. PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger
    88. PropertyChanges { target: recipe; detailsOpacity: 1; x: 0 } // Make details visible
    89. PropertyChanges { target: recipe; height: listView.height } // Fill the entire list area with the detailed view
    90.  
    91. // Move the list so that this item is at the top.
    92. PropertyChanges { target: recipe.ListView.view; explicit: true; contentY: recipe.y }
    93. PropertyChanges { target: recipe.ListView.view; }
    94.  
    95. // Disallow flicking while we're in detailed view
    96. PropertyChanges { target: recipe.ListView.view; interactive: false }
    97. }
    98.  
    99. transitions: Transition {
    100. // Make the state changes smooth
    101. ParallelAnimation {
    102. ColorAnimation { property: "color"; duration: 500 }
    103. NumberAnimation { duration: 300; properties: "detailsOpacity,x,contentY,height,width" }
    104. }
    105. }
    106. }
    107. }
    108. // The actual list
    109. ListView {
    110. id: listView
    111. anchors.fill: parent
    112. model: RecipesModel {}
    113. delegate: recipeDelegate
    114. }
    115. }
    To copy to clipboard, switch view to plain text mode 

    I have 9 different ShaderEffects, but I can only add one to all cells (code above). How can I assign each cell individual ShaderEffect?

  6. #6
    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: listview + shader

    There are many solutions... For example you could use VisualItemModel.
    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: 8
    Last Post: 28th January 2014, 08:09
  2. QPainter and Shader
    By shetan in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2011, 08:33
  3. Geometry shader with QT4.7
    By saraksh in forum General Programming
    Replies: 3
    Last Post: 28th March 2011, 16:40
  4. Fragment shader with 2d
    By krzat in forum Newbie
    Replies: 1
    Last Post: 20th December 2010, 21:37
  5. Node Shader Editor
    By AMDx64BT in forum Newbie
    Replies: 1
    Last Post: 6th December 2009, 22:30

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.