0

I have some difficulties to create my UI.

What I need :

1 QTabWidget with 3 QWidget as tabs. One of these Widget contains QPushButtons, QLineEdits, and have to contain another QTabWidget.

My problem :

Where I've sucess on my other QTabWidget, this one is not appearing. I've manually put QPushButton and QLineEdit in the .ui file. Now I want to dynamically create a QTabWidget on this same page.

My page code :

namespace Ui
{
class cImageInterface;
} 

class cImageInterface : public QWidget
{
    Q_OBJECT

public:
    cImageInterface();
    ~cImageInterface();

private:
    Ui::cImageInterface* ui;

cAppTabWidget* tabW_Application;
};

Constructor :

cImageInterface::cImageInterface() : ui(new Ui::cImageInterface)
{
  tabW_Application = new cAppTabWidget(this);

  ui->setupUi(this);
}

QTabWidget code :

class cAppTabWidget : public QTabWidget
{
    Q_OBJECT

public:
    explicit cAppTabWidget(QWidget* parent);
    ~cAppTabWidget();

protected:

private:
Ui::cAppTabWidget* ui;
cAppInterface* tab_Application;
int m_NbTab;
};

Contructor :

cAppTabWidget::cAppTabWidget(QWidget* parent)
                            : ui(new Ui::cAppTabWidget)
                            , tab_Application(new cAppInterface)
                            , m_NbTab(1)
{
  this->setGeometry(0, 230, 800, 360);
  this->addTab(tab_Application, "App5896");
}

cAppInterface is just a QWidget derived class, with only a setupUi in the constructor. I'm able to see my QTabWidget with show() but I'm not able to put it inside my page.

Thanks

MokaT
  • 1,416
  • 16
  • 37
  • Hummm, is it possible to have 2 layout by page ? or only one but with x, y, etc values ? because this is not what I want : http://imgur.com/oZ7ASYY EDIT: I think I'm stupid and I have found the solution. Will update if it's OK – MokaT Mar 06 '14 at 14:20
  • It's not working, I've put the layout into the .ui file, and `ui->appTabLayout->addWidget(tabW_Application);` into `cImageInterface` constructor, it's compiling, but I've a `core dumped` error – MokaT Mar 06 '14 at 14:35
  • 1
    Are you doing `ui->appTabLayout->addWidget(tabW_Application);` before `ui->setupUi(this)`? You cannot access `ui` members before you call `setupUi`. – thuga Mar 06 '14 at 14:55
  • You rock. Thanks. I'll accept my own answer as soon as I can. – MokaT Mar 06 '14 at 15:13

1 Answers1

1

Thanks to thuga for helping me.

The solution was to put a Layout into cImageInterface and then put the QTabWidget in it.

I've faced a problem by tring to create it in my code, so I've put it in the .ui file.

<layout class="QVBoxLayout" name="appTabLayout">
<property name="sizeConstraint">
 <enum>QLayout::SetNoConstraint</enum>
</property>

and then you can :

cImageInterface::cImageInterface() : ui(new Ui::cImageInterface)
{
  tabW_Application = new cAppTabWidget(this);

  ui->setupUi(this);

  ui->appTabLayout->addWidget(tabW_Application);
}
MokaT
  • 1,416
  • 16
  • 37