Results 1 to 5 of 5

Thread: Remove drawed lines with Repeater on ComboBox value changed

  1. #1
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Remove drawed lines with Repeater on ComboBox value changed

    This is the code to repeatedly dray lines on increasing the value on a ComboBox. But how can I delete the number of lines on decreasing this value?
    main.qml
    Qt Code:
    1. ComboBox {
    2. id: combo
    3. editable: false
    4. model: ListModel {
    5. id: numoflines
    6. ListElement { text: "1"; color: "Black" }
    7. ListElement { text: "2"; color: "Black" }
    8. ListElement { text: "3"; color: "Black" }
    9. ListElement { text: "4"; color: "Black" }
    10. ListElement { text: "5"; color: "Black" }
    11. ListElement { text: "6"; color: "Black" }
    12. ListElement { text: "7"; color: "Black" }
    13. }
    14. onAccepted: {
    15. if (combo.find(currentText) === -1) {
    16. model.append({text: editText})
    17. currentIndex = combo.find(editText)
    18. }
    19. }
    20. onCurrentTextChanged: {
    21. Global.numoflines = parseInt(currentIndex) + 1;
    22. console.log(Global.numoflines);
    23. Qt.createComponent("Analysis.qml").createObject(parent), {x: 100, y: 200};
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 


    Analysis.qml:
    Qt Code:
    1. Rectangle {
    2. id: base;
    3. x: 50;
    4. y: 480;
    5.  
    6. Column {
    7. spacing: -12;
    8.  
    9. Repeater {
    10. model: Global.numoflines;
    11. delegate: Rectangle {
    12. width: 800;
    13. height: 1;
    14. //color: "white";
    15. border { width: 1; color: "black" }
    16. radius: 3;
    17.  
    18. }
    19.  
    20. }
    21.  
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove drawed lines with Repeater on ComboBox value changed

    The repeater will always create as many element as its model says.

    Since your model is a simple number, just decrement that number.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Remove drawed lines with Repeater on ComboBox value changed

    Once some number of lines is drawn, they will not be deleted when a smaller number of lines is given to the model. So how to delete them and start drawing again?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove drawed lines with Repeater on ComboBox value changed

    A Repeater that operates on a primitive model, a number or a list, will always recreate the number of delegates for the current model's count.

    I.e. if the number changes from 1 to 2, it will delete all delegates and create 2.
    If the number changes from 2 to 1, it will delete all delegates and create 1.

    In your code the most puzzlng thing is why you create a new additional Analysis component every time the combobox changes.

    Cheers,
    _

  5. #5
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Remove drawed lines with Repeater on ComboBox value changed

    SOLVED. Thank you.
    Last edited by bchinfosieeuw; 10th August 2016 at 15:38.

Similar Threads

  1. PropertyChanges on repeater elements
    By joko in forum Qt Quick
    Replies: 4
    Last Post: 15th October 2014, 11:36
  2. QPainter doing a distortion in drawed pixmap
    By Momergil in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2014, 12:44
  3. ComboBox with lines
    By Braunstein in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2010, 08:12
  4. Remove Duplicate Lines in a file
    By nmuntz in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2009, 00:04
  5. how to save somtihing drawed on QPaiter to an image?
    By cxl2253 in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2006, 09:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.