[SOLVED] Adding my own widget to Qt designer generated code
-
I am trying to add a Dial widget that I have designed by inheriting from QWidget to an existing Qt generated code. I am following this post: "Add widgets manually to Qt designer generated code".
However the instructions in the post work for those simple controls, but they do not seem to work for my own widget, why?
What do I have to do to add my own widget to a Main window or even better to a Tab within the main window?Thanks
m -
Hi,
Please show us what you tried; it's impossible to say what's wrong otherwise
-
Ok, before going into how to add controls to a tab widget within the main window, I will concentrate on the following code:
#include "boatsimcontrol.h"
#include "ui_boatsimcontrol.h"
#include "MyNeedle.h"BoatSimControl::BoatSimControl(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::BoatSimControl)
{
ui->setupUi(this);MyNeedle needle; QHBoxLayout *btnLayout = new QHBoxLayout; btnLayout->addStretch(); btnLayout->addWidget(&needle); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addLayout(btnLayout); this->centralWidget()->setLayout(mainLayout);
}
Unless I am missing out something from the post I mentioned in my first comment, this should allow me to display a MyNeedle into the main window. Am I correct?
Thanks
M -
No, your object "needle" has been destroyed before you can see it.
-
Ops, local variable is destroyed once we get out of the constructor scope. Apologies to the C++ programmer :-). Thanks for spotting this out.
-
Place [SOLVED] in front of your first post, keeps us from unnecessary reading this post.