Solved Add widget from custom class to MainWindow
-
-
@mrjj I know, but it complains:
-
@Tamfub
Hi
the first parameter needs to be a QLabel and u give it a char *
also it seems that ip_field is not pointer ? -
@mrjj Actually it is ok with the
Char*
in place of theQLabel
, so I would put that apart for now.
I tried to:-
declare
IPCtrl *ip_field
(a pointer, as you suggested) inmainwindow.h
-
write
ui->formLayout->addRow("IP Address", ip_field->window()); ip_field->show();
(then with the arrows in place of the dots) inmainwindow.cpp
the application starts but the UI won't just appear...
-
-
Ok the window() part makes no sense to me.
Looking at the code, it just seems like a normal custom widget.
Did you change the code shown on SO or used it as is ? -
@mrjj I used it as is, no changes.
-
@Tamfub
Ok i did fast test.
It just compiles so not sure why you get so much grief from it :)ui->formLayout->addRow("test", field);
test project.
https://www.dropbox.com/s/v0a5rdlkzi3igvb/IPCtrlTEst.zip?dl=0 -
@mrjj Ok, it worked also for me now, the error in
addRow
disappeares whenip_field
is declared as a pointer. I did not try this XDThank you very much!
-
@Tamfub
Np :)
yes it must be pointer OR you must use the & to take address but
due to how deletion works, it's best to use pointer :) -
@mrjj Got it! Do you know why the right border of the textEdit is not visible?
-
@Tamfub
It seems the last Edit touches the QFrames border.
but even if i make it HUGE, it still happens so its
its seems to be due to
pLayout->setContentsMargins( 0, 0, 0, 0 );
so you can fix it with
pLayout->setContentsMargins( 0, 0, 1, 0 );
Seems not to give ill side effects.ps. in
IPCtrl::IPCtrl(QWidget *parent) : QFrame(parent) -
@mrjj Fine, thank you again :)
-
@Tamfub
Np.
please mark as solved if you got it working :)