0

I have an application which uses multiple tabs. I used QTabWidget. On some tabs I needed to show tables, so I used QTableWidget.

The code snippet is:

QWidget *qwgt = qPreviewTabs->widget(Index);
QTableWidget *qDrvTab = new QTableWidget();
....
....
....
QVBoxLayout *vbLyt = new QVBoxLayout();
vbLyt->addWidget(qDrvTab);
qwgt->setLayout(vbLyt); 

When I add push buttons and tree widgets they all appear on the specified tab without any problem. Only the QTableWidget refuses to show.

Daniel Hedberg
  • 5,677
  • 4
  • 36
  • 61
hiranes
  • 17
  • 10
  • Where are you creating the `QTableWidget`? What is `qDrvTab`? Can you show us an example of a successful widget insertion into the tab, and the failed table widget one? – cmannett85 May 25 '12 at 08:37
  • Oops sorry..qDrvTab is the table. I have edited the code snippet now. This is the failing code, in the sense the Table doesn't get shown. If i add any other widget to the Layout its showing. only Table doesnt work. – hiranes May 25 '12 at 08:45

1 Answers1

2
A table with no rows and columns is a void.

So do

qDrvTab->setRowCount(no_of_rows);
qDrvTab->setColumnCount(no_of_cols);

before adding it to layout.

Now you can see your Tablewidget in layout.

ScarCode
  • 3,074
  • 3
  • 19
  • 32