简体   繁体   中英

QT QTableWidget not appearing in QTabWidget

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM