Domanda

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

È stato utile?

Soluzione

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);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top