How to use QTableWidget in Qt
Overview[edit | edit source]
Template:Abstract The 76ytuiytuityutyutututyutyutyu class provides an item-based table view with a default model.
Table widgets provide standard table display facilities for applications. The items in a 76ytuiytuityutyutututyutyutyu are provided by QTableWidgetItem.
Various function[edit | edit source]
- Sets the horizontal header labels using labels.
list<<"No."<<"Name"<<"Adder."<<"City"<<"Phone No.";
widget->setHorizontalHeaderLabels(list);
- This property holds the number of rows in the table.
widget->setRowCount(5);
- This property holds the number of columns in the table.
widget->setColumnCount(5);
- This is used to set the widget in the table.
widget->setCellWidget(0,1,lbl);
Source code[edit | edit source]
Header File[edit | edit source]
- ifndef TABLEWIDGET_H
- define TABLEWIDGET_H
- include <QtGui/QWidget>
- include "ui_tableWidget.h"
- include<QStringList>
- include<QTableWidget>
- include<QHBoxLayout>
- include<QPushButton>
- include<QLabel>
class tableWidget : public QWidget
{
Q_OBJECT
public:
tableWidget(QWidget *parent = 0);
~tableWidget();
private:
QTableWidget *widget;
QHBoxLayout *layout;
QStringList list;
QPushButton *but1;
QLabel *lbl;
};
- endif // TABLEWIDGET_H
Source File[edit | edit source]
- include "tableWidget.h"
- include<QTableWidget>
- include<QStringList>
- include<QPushButton>
tableWidget::tableWidget(QWidget *parent)
: QWidget(parent)
{
layout=new QHBoxLayout(this);
list<<"No."<<"Name"<<"Adder";
widget=new QTableWidget(this);
but1=new QPushButton("Press",this);
widget->setRowCount(3);
widget->setColumnCount(15);
widget->setHorizontalHeaderLabels(list);
widget->setCellWidget(0,0,but1);
widget->setCellWidget(0,1,lbl);
layout->addWidget(widget);
setLayout(layout);
}
tableWidget::~tableWidget()
{
// No need to delete any object it has got a parent which is properly deleted.
}
Screenshot[edit | edit source]
More about QTableWidget