QFrame does not display in UI properly
-
@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.
@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 aQDialog
(which itself is not shown at this point). Widgets should not beshow()
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?
-
@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 aQDialog
(which itself is not shown at this point). Widgets should not beshow()
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?
@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.
-
@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.
@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.... -
@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....@JonB I see. Again, thank you for your time and patience.
-
@JonB I see. Again, thank you for your time and patience.
@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 aboveI suggested to you to use setGeometry() in your other thread...
I would be looking into that if I were you :)
-
@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 aboveI suggested to you to use setGeometry() in your other thread...
I would be looking into that if I were you :)
@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:
(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.
-
@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:
(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.
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.
-
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.
@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 themainLine->setParent(this);
you claim makes it work!Would you care to show your complete, working code for this frame/dialog? :)
-
@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 themainLine->setParent(this);
you claim makes it work!Would you care to show your complete, working code for this frame/dialog? :)
@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.
-
@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.
@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! :)