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. QFrame does not display in UI properly
Forum Updated to NodeBB v4.3 + New Features

QFrame does not display in UI properly

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 1.5k Views
  • 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.
  • Dummie1138D Dummie1138

    @JonB @jsulm Here is more code, thanks for your patience and time.

    NewConfig::NewConfig(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::NewConfig)
    {
        setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);
        ui->setupUi(this);
        this->move(0, 0);
    
        //Build the main line.
        QFrame *mainLine = new QFrame(this);
        QRect lineRect = QRect(20, 160, 400, 40);
        mainLine->setFrameRect(*lineRect);
        //mainLine->setGeometry(20, 160, 400, 40);  //This was added based on jsulm's suggestions. I've disabled it for this post.
        mainLine->setLineWidth(5);
        mainLine->setFrameStyle(QFrame::Raised);
    
        qDebug() << lineRect;
        qDebug() << mainLine->frameRect();
        mainLine->show();
    }
    

    The output is:

    QRect(20,160 400x40)
    QRect(0,0 400x40)
    

    I have also restarted Qt Creator and noticed the warning having disappeared. Again, thank you for your time and patience, and please let me know if more information is required.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #5

    @Dummie1138 said in QFrame is unused:

    QRect lineRect = QRect(20, 160, 400, 40);
    mainLine->setFrameRect(*lineRect);
    

    For a start the above will not compile....

    mainLine->show();

    You are attempting to show a QFrame here, but you are inside the constructor of a QDialog (which itself is not shown at this point). Widgets should not be show()n in widget constructors. Where do you actually show the dialog?

    You have just added:

    The output is:

    How do you get output from code which as shown will not compile?

    Dummie1138D 1 Reply Last reply
    0
    • JonBJ JonB

      @Dummie1138 said in QFrame is unused:

      QRect lineRect = QRect(20, 160, 400, 40);
      mainLine->setFrameRect(*lineRect);
      

      For a start the above will not compile....

      mainLine->show();

      You are attempting to show a QFrame here, but you are inside the constructor of a QDialog (which itself is not shown at this point). Widgets should not be show()n in widget constructors. Where do you actually show the dialog?

      You have just added:

      The output is:

      How do you get output from code which as shown will not compile?

      Dummie1138D Offline
      Dummie1138D Offline
      Dummie1138
      wrote on last edited by Dummie1138
      #6

      @JonB Sorry, that *lineRect is a mistype. The proper one is just "lineRect".

      My intention is to be able to show this QFrame in my ui file, NewConfig, as a bar, if this helps.

      JonBJ 1 Reply Last reply
      0
      • Dummie1138D Dummie1138

        @JonB Sorry, that *lineRect is a mistype. The proper one is just "lineRect".

        My intention is to be able to show this QFrame in my ui file, NewConfig, as a bar, if this helps.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #7

        @Dummie1138
        Since you are typing your code in and not pasting it, I will leave it to others answer. Too many years of replying to people who do not paste their code and after we all work on it discover it isn't actually what their code reads....

        Dummie1138D 1 Reply Last reply
        0
        • JonBJ JonB

          @Dummie1138
          Since you are typing your code in and not pasting it, I will leave it to others answer. Too many years of replying to people who do not paste their code and after we all work on it discover it isn't actually what their code reads....

          Dummie1138D Offline
          Dummie1138D Offline
          Dummie1138
          wrote on last edited by
          #8

          @JonB I see. Again, thank you for your time and patience.

          JonBJ 1 Reply Last reply
          0
          • Dummie1138D Dummie1138

            @JonB I see. Again, thank you for your time and patience.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #9

            @Dummie1138
            You have responded politely, and I accept that :) Honestly, it's really important to actually copy & paste code when you want help, you are not the first person to have made a mistake when typing in instead, it's too unreliable!

            I don't understand what it is that you do or do not see when/where?

            My intention is to be able to show this QFrame in my ui file, NewConfig, as a bar, if this helps.

            Are you expecting to see the QFrame visible when you are in the Designer?? That will not happen, this is run-time code. You would only see it when you show the dialog at runtime. Are you doing so, and is that when it is shown wrong somehow?

            I have not used QFrame. If @jsulm says above

            I suggested to you to use setGeometry() in your other thread...

            I would be looking into that if I were you :)

            Dummie1138D 1 Reply Last reply
            0
            • JonBJ JonB

              @Dummie1138
              You have responded politely, and I accept that :) Honestly, it's really important to actually copy & paste code when you want help, you are not the first person to have made a mistake when typing in instead, it's too unreliable!

              I don't understand what it is that you do or do not see when/where?

              My intention is to be able to show this QFrame in my ui file, NewConfig, as a bar, if this helps.

              Are you expecting to see the QFrame visible when you are in the Designer?? That will not happen, this is run-time code. You would only see it when you show the dialog at runtime. Are you doing so, and is that when it is shown wrong somehow?

              I have not used QFrame. If @jsulm says above

              I suggested to you to use setGeometry() in your other thread...

              I would be looking into that if I were you :)

              Dummie1138D Offline
              Dummie1138D Offline
              Dummie1138
              wrote on last edited by
              #10

              @JonB I will make sure to copy code instead of typing it, thanks for the advice.

              Are you expecting to see the QFrame visible when you are in the Designer?? That will not happen, this is run-time code. You would only see it when you show the dialog at runtime. Are you doing so, and is that when it is shown wrong somehow?
              I know the QFrame is run-time code, my issue is that the QFrame is not visible during run-time.

              I have modified my code to this following, switching to setGeometry.

                  QFrame *mainLine = new QFrame(this, Qt::Widget);
                  mainLine->setGeometry(20, 160, 400, 40);
                  mainLine->setLineWidth(5);
                  mainLine->setFrameStyle(QFrame::Raised);
              
                  qDebug() << mainLine->frameRect();
                  mainLine->show();
              

              This is the location on my ui where the QFrame is supposed to be:
              4e14ebc5-ef2e-4188-927e-697fb230d317-image.png
              (Sadly I cannot show the entire thing. I hope this remains somewhat helpful.)

              And this is what my output looks like.

              QRect(0,0 400x40)
              

              Again, please let me know if more information is required.

              Dummie1138D 1 Reply Last reply
              0
              • Dummie1138D Dummie1138

                @JonB I will make sure to copy code instead of typing it, thanks for the advice.

                Are you expecting to see the QFrame visible when you are in the Designer?? That will not happen, this is run-time code. You would only see it when you show the dialog at runtime. Are you doing so, and is that when it is shown wrong somehow?
                I know the QFrame is run-time code, my issue is that the QFrame is not visible during run-time.

                I have modified my code to this following, switching to setGeometry.

                    QFrame *mainLine = new QFrame(this, Qt::Widget);
                    mainLine->setGeometry(20, 160, 400, 40);
                    mainLine->setLineWidth(5);
                    mainLine->setFrameStyle(QFrame::Raised);
                
                    qDebug() << mainLine->frameRect();
                    mainLine->show();
                

                This is the location on my ui where the QFrame is supposed to be:
                4e14ebc5-ef2e-4188-927e-697fb230d317-image.png
                (Sadly I cannot show the entire thing. I hope this remains somewhat helpful.)

                And this is what my output looks like.

                QRect(0,0 400x40)
                

                Again, please let me know if more information is required.

                Dummie1138D Offline
                Dummie1138D Offline
                Dummie1138
                wrote on last edited by
                #11

                This issue has been resolved.

                By adding this line to the QFrame, the QFrame was finally displayed.

                mainLine->setParent(this);
                

                The reason for the output of

                qDebug << mainLine->frameRect();
                

                placing the location of the Rect at 0,0 is not due to a lack of response but because the Rect is always parented to the QFrame, which means it's location relative to the QFrame is always 0,0.

                JonBJ 1 Reply Last reply
                0
                • Dummie1138D Dummie1138

                  This issue has been resolved.

                  By adding this line to the QFrame, the QFrame was finally displayed.

                  mainLine->setParent(this);
                  

                  The reason for the output of

                  qDebug << mainLine->frameRect();
                  

                  placing the location of the Rect at 0,0 is not due to a lack of response but because the Rect is always parented to the QFrame, which means it's location relative to the QFrame is always 0,0.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #12

                  @Dummie1138 said in QFrame does not display in UI properly:

                  mainLine->setParent(this);

                  Well, I truly do not see how this could make any difference! I have tried it in my copy of your code I am playing with and it certainly makes no difference. Since you already had QFrame *mainLine = new QFrame(this) that has already done the mainLine->setParent(this); you claim makes it work!

                  Would you care to show your complete, working code for this frame/dialog? :)

                  Dummie1138D 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Dummie1138 said in QFrame does not display in UI properly:

                    mainLine->setParent(this);

                    Well, I truly do not see how this could make any difference! I have tried it in my copy of your code I am playing with and it certainly makes no difference. Since you already had QFrame *mainLine = new QFrame(this) that has already done the mainLine->setParent(this); you claim makes it work!

                    Would you care to show your complete, working code for this frame/dialog? :)

                    Dummie1138D Offline
                    Dummie1138D Offline
                    Dummie1138
                    wrote on last edited by Dummie1138
                    #13

                    @JonB And now it doesn't work again.

                    Current code, as much as I can show:

                    NewConfig::NewConfig(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::NewConfig)
                    {
                        setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);
                        ui->setupUi(this);
                        this->move(0, 0);
                    
                        //Build the main line.
                        QFrame *frontLine = new QFrame(this);
                        frontLine->setGeometry(0, 0, 400, 40);
                        frontLine->setLineWidth(10);
                        frontLine->setFrameStyle(QFrame::Raised);
                        frontLine->setParent(this);  //I was working under the impression that the (this) at QFrame initialization is the same as setParent(this).
                    
                        frontLine->show();
                        QLabel *labelOne = new QLabel("REEEE", this);
                        labelOne->move(200, 200);
                    }
                    

                    Edit:

                    frontLine->setStyleSheet("border: 10px solid #0000FF;")
                    

                    was added to the QFrame code. It now displays. Quite the silly oversight on my behalf.

                    JonBJ 1 Reply Last reply
                    0
                    • Dummie1138D Dummie1138

                      @JonB And now it doesn't work again.

                      Current code, as much as I can show:

                      NewConfig::NewConfig(QWidget *parent) :
                          QDialog(parent),
                          ui(new Ui::NewConfig)
                      {
                          setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint);
                          ui->setupUi(this);
                          this->move(0, 0);
                      
                          //Build the main line.
                          QFrame *frontLine = new QFrame(this);
                          frontLine->setGeometry(0, 0, 400, 40);
                          frontLine->setLineWidth(10);
                          frontLine->setFrameStyle(QFrame::Raised);
                          frontLine->setParent(this);  //I was working under the impression that the (this) at QFrame initialization is the same as setParent(this).
                      
                          frontLine->show();
                          QLabel *labelOne = new QLabel("REEEE", this);
                          labelOne->move(200, 200);
                      }
                      

                      Edit:

                      frontLine->setStyleSheet("border: 10px solid #0000FF;")
                      

                      was added to the QFrame code. It now displays. Quite the silly oversight on my behalf.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #14

                      @Dummie1138 said in QFrame does not display in UI properly:

                      frontLine->setParent(this); //I was working under the impression that the (this) at QFrame initialization is the same as setParent(this).

                      Indeed, as I said that was already the case! As can be verified by preceding this line with:

                      Q_ASSERT(frontLine->parent() == this);

                      So that setParent() can be removed!

                      Nor is the frontLine->show(); needed, and I would not put it into this constructor personally.

                      frontLine->setStyleSheet("border: 10px solid #0000FF;")

                      Yep, that made all the difference to visibility! :)

                      1 Reply Last reply
                      0

                      • Login

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