Results 1 to 3 of 3

Thread: QML with C++ backend - dynamic components

  1. #1
    Join Date
    Sep 2016
    Posts
    6
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default QML with C++ backend - dynamic components

    I am quite new to QML and am trying to write some code that features dynamic components with a C++ backend.

    Let's assume I want to write a program where:

    The user presses a button that opens a dialogue where he fills in a name N, and position X, Y
    When OK is pressed a component that is a rectangle with the text N from the dialogue is created at position X,Y with color C="blue"
    N rectangles can be created by using the steps above (fully dynamic)
    There is a C++ backed that has a list of these rectangles and can by some C++ logic change the X,Y,C properties of the rectangles or even add new rectangles or delete some created ones.
    I've read probably all documents that I could google that describe QML and C++ integration but didn't find an example that was close enough to what I need.

    I appreciate your guidelines of how to implement the desired behavior.

    Thanks in advance!
    Ben

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

    Default Re: QML with C++ backend - dynamic components

    I would say you create a custom model that has X, Y and N for each entry and use a Repeater element in QML to create Rectangle elements for each entry in the model, using the model's data.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    benberli (5th September 2016)

  4. #3
    Join Date
    Sep 2016
    Posts
    6
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QML with C++ backend - dynamic components

    Thank you, this helped a lot and I have something basic working

Similar Threads

  1. Replies: 3
    Last Post: 30th March 2016, 09:40
  2. Replies: 8
    Last Post: 14th June 2013, 11:16
  3. Replies: 1
    Last Post: 20th October 2012, 12:47
  4. Create dynamic QML components from within C++! How to?
    By jackmack in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2012, 09:52
  5. Change phonon backend to vlc backend
    By stereoMatching in forum Newbie
    Replies: 1
    Last Post: 8th September 2012, 06:10

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.