Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding children to a QWidget, but not showing...
Forum Updated to NodeBB v4.3 + New Features

Adding children to a QWidget, but not showing...

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SPlatten
    wrote on 6 Feb 2021, 13:14 last edited by SPlatten 2 Jun 2021, 13:17
    #1

    I have a Window that I am creating programmatically, this bit works fine the window is rendered with Close, Minimise and Maximise widgets. I'm trying to add additional widgets programmatically to the window in the display area. I can see that after creating and adding the new widgets by calling:

    QObjectList objList = pobjWidget->children();
    

    The objList length is incrementing. I've added four instances of QLabel to the Window, however for some reason that are not showing. Here is the styles I have applied to each label:

        static const char scszLabelProperties[] = 
                            "QLabel { text-align:left;"
                                     "vertical-align: text-top;"
                                     "border:0px;"
                                     "color:#000000;"
                                     "format:rich;"
                                     "text-decoration:none; }";
    

    When the label is created a pointer to the parent Widget / Window is passed QLabel constructor. Can anyone suggest what might be wrong?

    I can post more source code if required, just let me know what?

    Kind Regards,
    Sy

    J 1 Reply Last reply 6 Feb 2021, 13:39
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Feb 2021, 14:00 last edited by
      #3

      Hi,

      Just passing a parent to a widget created at run time won't make it visible. You have to explicitly call show on it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 6 Feb 2021, 14:12
      1
      • S SPlatten
        6 Feb 2021, 13:14

        I have a Window that I am creating programmatically, this bit works fine the window is rendered with Close, Minimise and Maximise widgets. I'm trying to add additional widgets programmatically to the window in the display area. I can see that after creating and adding the new widgets by calling:

        QObjectList objList = pobjWidget->children();
        

        The objList length is incrementing. I've added four instances of QLabel to the Window, however for some reason that are not showing. Here is the styles I have applied to each label:

            static const char scszLabelProperties[] = 
                                "QLabel { text-align:left;"
                                         "vertical-align: text-top;"
                                         "border:0px;"
                                         "color:#000000;"
                                         "format:rich;"
                                         "text-decoration:none; }";
        

        When the label is created a pointer to the parent Widget / Window is passed QLabel constructor. Can anyone suggest what might be wrong?

        I can post more source code if required, just let me know what?

        J Offline
        J Offline
        JonB
        wrote on 6 Feb 2021, 13:39 last edited by JonB 2 Jun 2021, 14:10
        #2

        @SPlatten
        Start by removing any stylesheet. Is this a stylesheet or a widget adding issue? If it's the adding, don't complicate by introducing/mentioning stylesheet

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 Feb 2021, 14:00 last edited by
          #3

          Hi,

          Just passing a parent to a widget created at run time won't make it visible. You have to explicitly call show on it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 6 Feb 2021, 14:12
          1
          • S SGaist
            6 Feb 2021, 14:00

            Hi,

            Just passing a parent to a widget created at run time won't make it visible. You have to explicitly call show on it.

            S Offline
            S Offline
            SPlatten
            wrote on 6 Feb 2021, 14:12 last edited by SPlatten 2 Jun 2021, 14:16
            #4

            @JonB , I started off with no stylesheet at all, thats why I added the style sheet.

            @SGaist , I also have the code:

                            if ( objList.length() == 0 ) {
                //No children
                                ptOffsets.setX(0);
                                ptOffsets.setY(0);
                            } else {
                //Set offset to last child
                                QWidget* pobjLastWidget = static_cast<QWidget*>(objList[objList.length() - 1]);
                                ptOffsets = pobjLastWidget->geometry().bottomLeft();
                            }
                //Get existing node geometry
                            QRect rctGeom = pobjNode->rctGetGeometry();
                //Offset into poisition
                            rctGeom.setTopLeft(ptOffsets);
                            pobjNode->setGeometry(rctGeom);
                            pobjNode->setVisible(true);
            

            Where pobjNode is a generic class that is used for all the widget types and each of the methods being called effect the widget, for example:

            void clsXMLnode::setGeometry(QRect& rrctGeom) {
                bool blnValid;
            
                if ( (blnValid = rrctGeom.isValid()) == true ) {
            //If there is a widget associated with this node set it's geometry
                    if ( mpobjWidget != nullptr ) {
                        mrctGeom = rrctGeom;
                        mblnPendingGeom = false;
                        mpobjWidget->setGeometry(mrctGeom);
                    } else {
                        blnValid = false;
                    }
                }
                if ( blnValid != true ) {
                    mblnPendingGeom = true;
                    mrctPending = rrctGeom;
                }
            }
            @SGaist , however, I just added:
            
                        QWidget* pobjChild = pobjNode->pobjGetWidget();
                        pobjChild->update();
                        pobjChild->show();
            
            And now they are showing, so I have a bug in my helper class which I will investigate, thank you.

            Kind Regards,
            Sy

            1 Reply Last reply
            0

            1/4

            6 Feb 2021, 13:14

            • Login

            • Login or register to search.
            1 out of 4
            • First post
              1/4
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved