Results 1 to 17 of 17

Thread: help on QSGGeometry

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: help on QSGGeometry

    Quote Originally Posted by wysota View Post
    Of course all that should be done in a declarative way
    Hi wysota,

    Please bear with me for I have some additional questions.

    Here's my current code:

    Qt Code:
    1. // WizardBar.cpp code snippet
    2. QSGNode *WizardBar::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
    3. {
    4. QSGNode *root = static_cast<QSGNode *>(oldNode);
    5. if(!root) root = new QSGNode;
    6.  
    7. QSGGeometry *geometry;
    8.  
    9. int height = WizardBar::height();
    10. int width = WizardBar::width();
    11.  
    12. int arrow = height / 2;
    13.  
    14. int pos = 0;
    15.  
    16. QColor backgroundColor = active_ ? activeBg_ : inactiveBg_;
    17.  
    18. switch (position_)
    19. {
    20. case FirstLabel:
    21. geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 5);
    22. geometry->setDrawingMode(GL_TRIANGLE_FAN);
    23. geometry->vertexDataAsPoint2D()[0].set(pos, 0);
    24. geometry->vertexDataAsPoint2D()[1].set(pos + width, 0);
    25. geometry->vertexDataAsPoint2D()[2].set(pos + arrow + width, arrow);
    26. geometry->vertexDataAsPoint2D()[3].set(pos + width, height);
    27. geometry->vertexDataAsPoint2D()[4].set(pos, height);
    28. break;
    29.  
    30. case LastLabel:
    31. geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 5);
    32. geometry->setDrawingMode(GL_TRIANGLE_FAN);
    33. geometry->vertexDataAsPoint2D()[0].set(pos + arrow, arrow);
    34. geometry->vertexDataAsPoint2D()[1].set(pos, 0);
    35. geometry->vertexDataAsPoint2D()[2].set(pos + width, 0);
    36. geometry->vertexDataAsPoint2D()[3].set(pos + width, height);
    37. geometry->vertexDataAsPoint2D()[4].set(pos, height);
    38. break;
    39.  
    40. default:
    41. geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 6);
    42. geometry->setDrawingMode(GL_TRIANGLE_FAN);
    43. geometry->vertexDataAsPoint2D()[0].set(pos + arrow, arrow);
    44. geometry->vertexDataAsPoint2D()[1].set(pos, 0);
    45. geometry->vertexDataAsPoint2D()[2].set(pos + width, 0);
    46. geometry->vertexDataAsPoint2D()[3].set(pos + arrow + width, arrow);
    47. geometry->vertexDataAsPoint2D()[4].set(pos + width, height);
    48. geometry->vertexDataAsPoint2D()[5].set(pos, height);
    49. break;
    50. }
    51.  
    52. root->appendChildNode(drawPolygon(geometry, backgroundColor));
    53.  
    54. return root;
    55. }
    56.  
    57. QSGNode *WizardBar::drawPolygon(QSGGeometry *geometry, const QColor &color)
    58. {
    59. QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
    60. material->setColor(color);
    61.  
    62. QSGGeometryNode *node = new QSGGeometryNode;
    63. node->setGeometry(geometry);
    64. node->setFlag(QSGNode::OwnsGeometry);
    65. node->setMaterial(material);
    66. node->setFlag(QSGNode::OwnsMaterial);
    67. return node;
    68. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. // qml page
    2. Item {
    3. id: container
    4.  
    5. property int conWidth: StaticData.screenWidth - header.anchors.leftMargin*2; // i can't get the implicit width of anchored items
    6. property int missingWidth: 0
    7. property int extraWidth: 0
    8.  
    9. function getWidth(rowWidth) {
    10. if (rowWidth <= conWidth) {
    11. missingWidth = 0;
    12. extraWidth = conWidth - rowWidth;
    13. } else {
    14. extraWidth = 0;
    15. missingWidth = rowWidth - conWidth
    16. }
    17. }
    18.  
    19. anchors {
    20. right: parent.right
    21. left: parent.left
    22. bottom: parent.bottom
    23. }
    24. clip: true
    25. height: 60
    26.  
    27. Row {
    28. id: barRow
    29.  
    30. property int rowWidth
    31. property int curIdx
    32.  
    33. spacing: 1
    34.  
    35. ListModel {
    36. id: barModel
    37.  
    38. ListElement {
    39. label: qsTr("Protocol")
    40. group: "protocols"
    41. }
    42. ListElement {
    43. label: qsTr("Host")
    44. group: "host"
    45. }
    46. ListElement {
    47. label: qsTr("Login")
    48. group: "login"
    49. }
    50. ListElement {
    51. label: qsTr("Proxy")
    52. group: "proxy"
    53. }
    54. ListElement {
    55. label: qsTr("Save")
    56. group: "save"
    57. }
    58. }
    59.  
    60. Component.onCompleted: {
    61. container.getWidth(rowWidth);
    62.  
    63. if (container.extraWidth > 0) {
    64. var addtlWidth = Math.floor(container.extraWidth/barModel.count)
    65. for (var i = 0; i <= barModel.count - 1; i++) {
    66. barRepeater.itemAt(i).width += addtlWidth ;
    67. }
    68. }
    69. }
    70.  
    71. Repeater {
    72. id: barRepeater
    73.  
    74. model: barModel
    75.  
    76. onItemAdded: {
    77. barRow.rowWidth += item.width;
    78. }
    79.  
    80. WizardBar {
    81. id: wizardBar
    82.  
    83. property bool mid: index != 0
    84. property bool curGroup: model.group === newConnPagesModel.curGroup // to synch with the wizard pages
    85.  
    86. onCurGroupChanged: {
    87. if (curGroup) barRow.curIdx = index;
    88. }
    89.  
    90. height: 60
    91. width: label.paintedWidth + 10
    92.  
    93. active: index <= barRow.curIdx
    94. position: index === 0 ? WizardBar.FirstLabel : ((index === (barModel.count - 1)) ? WizardBar.LastLabel : WizardBar.MiddleLabel) // labels are enum in class which indicates the shape of the arrow to be drawn
    95.  
    96. Item { // created as text container so that the arrow part will be excluded
    97. id: labelItem
    98.  
    99. x: index != 0 ? parent.height/2 : 0
    100. width: index != 0 ? parent.width - parent.height/2 : parent.width
    101. height: parent.height
    102.  
    103. Text
    104. {
    105. id: label
    106. anchors.centerIn: parent
    107.  
    108. color: wizardBar.active ? Colors.text.title.normal : Colors.text.title.disabled
    109. font { pixelSize: Fonts.fontSize; family: Fonts.fontFamily }
    110.  
    111. text: model.label
    112. }
    113. }
    114. }
    115. }
    116. }
    117. }
    To copy to clipboard, switch view to plain text mode 

    Questions:
    1. I connected the widthChanged() signal into update(). The label font pixelSize, scales based on screen diagonal width. However, seems like it is not updating when label.paintedWidth and screen orientation changes.
    2. Is there a way to clear or delete previous render or force to clear all the delegate items of the repeater because they're not being cleared. I mean, I can still see the original render when I tried increasing the window size.
    3. I'm still having a hard time figuring out how to move the model elements upon navigation and placing the dotted arrow if there is a missing element either on left or right or both. Can you give more tips please.
    4. I tried putting a permanent dotted arrows on both sides of the main Item and control its visibility on missingWidth and adjust the width of those visible elements, however I still can get it to work, which goes back also to #3 problem in moving the elements. Is this even possible? Any tips?

    Thank you!
    Last edited by joko; 27th April 2015 at 18:17.

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

    Default Re: help on QSGGeometry

    Quote Originally Posted by joko View Post
    Questions:
    1. I connected the widthChanged() signal into update(). The label font pixelSize, scales based on screen diagonal width. However, seems like it is not updating when label.paintedWidth and screen orientation changes.
    The diagonal length doesn't change when orientation changes. You should base your font on height value.

    2. Is there a way to clear or delete previous render or force to clear all the delegate items of the repeater because they're not being cleared. I mean, I can still see the original render when I tried increasing the window size.
    Repeater will recreate its items when the model is changed. However it seems to me you should just update your items in the situation you are describing.

    3. I'm still having a hard time figuring out how to move the model elements upon navigation and placing the dotted arrow if there is a missing element either on left or right or both. Can you give more tips please.
    I would have to sit down and try it myself. I don't know your exact use case, maybe your current approach doesn't fit it that well.

    4. I tried putting a permanent dotted arrows on both sides of the main Item and control its visibility on missingWidth and adjust the width of those visible elements, however I still can get it to work, which goes back also to #3 problem in moving the elements. Is this even possible? Any tips?
    What is it that you can't get to work? Hiding items?
    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. The following user says thank you to wysota for this useful post:

    joko (5th May 2015)

Similar Threads

  1. Need help with two questions please
    By phantom2323 in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2012, 11:33
  2. Qt like VS add-in questions
    By GreenScape in forum General Programming
    Replies: 0
    Last Post: 4th August 2010, 09:28
  3. Sql questions
    By Nb2Qt in forum Qt Programming
    Replies: 4
    Last Post: 15th February 2007, 22:53

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.