Results 1 to 3 of 3

Thread: Promoted Widget within a Promoted Widget programmatically

  1. #1
    Join Date
    Sep 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Smile Promoted Widget within a Promoted Widget programmatically

    Hi

    Widget Promotion

    Based on several forums I managed to promote a graphicsView accordingly.
    The issue comes when within the promoted class I need to create a QLabel (within the graphicsView) that itself needs to be promoted.

    1. Promote Graphics View (through the designer)
    2. Add QLabel Widget within graphicsView (programatically)
    Qt Code:
    1. label= new QLabel();
    2. label->setFixedSize(320, 320);
    3. label->setText("Test Label");
    4. proxy = myScene->addWidget(label);
    5. proxy->setZValue(0);
    To copy to clipboard, switch view to plain text mode 
    3. try to promote the generated label (That is within the graphicsView) to another class in code
    Since i only have access to the label in the code and not via the designer.

    How do I promote a QLabel to a specified class within code? (Not through the designer)

    Your assistance is appreciated

    Regards
    Last edited by ByForeward; 16th September 2015 at 16:24. Reason: updated title

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Promoted Widget within a Promoted Widget programmatically

    There is no such thing as widget promotion in code.

    Widget promotion, in the context of Designer, is the mechanism by which the user can add a widget of some class C in design mode and make Designer, in the generated code setting up this UI, actually instantiate a specified subclass of C. E.g. if you have a QLabel-derived class MyLabel, you can add a QLabel in design mode and promote it to MyLabel. You will be limited, in design mode, to the QLabel interface (properties, signals), but Designer will generate code that instantiates a MyLabel and sets its QLabel-inherited properties accordingly.

    If you write the code directly, just instantiate the correct class. Instead of
    Qt Code:
    1. QLabel *label = new QLabel();
    To copy to clipboard, switch view to plain text mode 
    , do something like
    Qt Code:
    1. MyLabel *label = new MyLabel();
    To copy to clipboard, switch view to plain text mode 

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

    ByForeward (16th September 2015)

  4. #3
    Join Date
    Sep 2015
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default [SOLVED] Promoted Widget within a Promoted Widget programmatically

    Yes Thanks,

    Your proposition of correctly instantiating a class would work.
    (I don't know why i did not think of that... I'm still learning the ropes, i guess)

    Thanks yeye
    Last edited by ByForeward; 16th September 2015 at 17:05.

Similar Threads

  1. Replies: 6
    Last Post: 24th October 2013, 19:08
  2. Replies: 6
    Last Post: 24th November 2011, 10:54
  3. Why dont see a Custom Widget Promoted ?
    By tonnot in forum Newbie
    Replies: 1
    Last Post: 27th October 2010, 14:24
  4. Promoted widgets in Qt Designer
    By martinb0820 in forum Qt Tools
    Replies: 1
    Last Post: 9th June 2010, 16:07
  5. Replies: 2
    Last Post: 20th March 2010, 19:22

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.