A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQTableWidget</id>
		<title>C++/Qt/QTableWidget - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQTableWidget"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QTableWidget&amp;action=history"/>
		<updated>2026-04-18T15:22:24Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QTableWidget&amp;diff=1036&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QTableWidget&amp;diff=1036&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QTableWidget&amp;diff=1037&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QTableWidget&amp;diff=1037&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:38Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Calculate the average and sum for QTableWidget==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QTableWidget;&lt;br /&gt;
class QTableWidgetItem;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void averageItems();&lt;br /&gt;
    void sumItems();&lt;br /&gt;
private:&lt;br /&gt;
    void setupTableItems();&lt;br /&gt;
    QAction *removeAction;&lt;br /&gt;
    QTableWidget *tableWidget;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;math.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    QMenu *itemsMenu = new QMenu(tr(&amp;quot;&amp;amp;Items&amp;quot;));&lt;br /&gt;
    QAction *sumItemsAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Sum Items&amp;quot;));&lt;br /&gt;
    QAction *averageItemsAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Average Items&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(itemsMenu);&lt;br /&gt;
&lt;br /&gt;
    tableWidget = new QTableWidget(12, 3, this);&lt;br /&gt;
    tableWidget-&amp;gt;setSelectionMode(QAbstractItemView::ExtendedSelection);&lt;br /&gt;
&lt;br /&gt;
    QTableWidgetItem *valuesHeaderItem = new QTableWidgetItem(tr(&amp;quot;Values&amp;quot;));&lt;br /&gt;
    tableWidget-&amp;gt;setHorizontalHeaderItem(0, valuesHeaderItem);&lt;br /&gt;
    valuesHeaderItem-&amp;gt;setTextAlignment(Qt::AlignVCenter);&lt;br /&gt;
    QTableWidgetItem *squaresHeaderItem = new QTableWidgetItem(tr(&amp;quot;Squares&amp;quot;));&lt;br /&gt;
    squaresHeaderItem-&amp;gt;setIcon(QIcon(QPixmap(&amp;quot;:/Images/squared.png&amp;quot;)));&lt;br /&gt;
    squaresHeaderItem-&amp;gt;setTextAlignment(Qt::AlignVCenter);&lt;br /&gt;
    QTableWidgetItem *cubesHeaderItem = new QTableWidgetItem(tr(&amp;quot;Cubes&amp;quot;));&lt;br /&gt;
    cubesHeaderItem-&amp;gt;setIcon(QIcon(QPixmap(&amp;quot;:/Images/cubed.png&amp;quot;)));&lt;br /&gt;
    cubesHeaderItem-&amp;gt;setTextAlignment(Qt::AlignVCenter);&lt;br /&gt;
    tableWidget-&amp;gt;setHorizontalHeaderItem(1, squaresHeaderItem);&lt;br /&gt;
    tableWidget-&amp;gt;setHorizontalHeaderItem(2, cubesHeaderItem);&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));&lt;br /&gt;
    connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems()));&lt;br /&gt;
    connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems()));&lt;br /&gt;
    setupTableItems();&lt;br /&gt;
    setCentralWidget(tableWidget);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Table Widget&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::setupTableItems()&lt;br /&gt;
{&lt;br /&gt;
    for (int row = 0; row &amp;lt; tableWidget-&amp;gt;rowCount()-1; ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; tableWidget-&amp;gt;columnCount(); ++column) {&lt;br /&gt;
    QTableWidgetItem *newItem = new QTableWidgetItem(tr(&amp;quot;%1&amp;quot;).arg(&lt;br /&gt;
        pow(row, column+1)));&lt;br /&gt;
    tableWidget-&amp;gt;setItem(row, column, newItem);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    for (int column = 0; column &amp;lt; tableWidget-&amp;gt;columnCount(); ++column) {&lt;br /&gt;
        QTableWidgetItem *newItem = new QTableWidgetItem;&lt;br /&gt;
        newItem-&amp;gt;setFlags(Qt::ItemIsEnabled);&lt;br /&gt;
        tableWidget-&amp;gt;setItem(tableWidget-&amp;gt;rowCount()-1, column, newItem);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::averageItems()&lt;br /&gt;
{&lt;br /&gt;
    QList&amp;lt;QTableWidgetItem *&amp;gt; selected = tableWidget-&amp;gt;selectedItems();&lt;br /&gt;
    QTableWidgetItem *item;&lt;br /&gt;
    int number = 0;&lt;br /&gt;
    double total = 0;&lt;br /&gt;
    foreach (item, selected) {&lt;br /&gt;
        bool ok;&lt;br /&gt;
        double value = item-&amp;gt;text().toDouble(&amp;amp;ok);&lt;br /&gt;
        &lt;br /&gt;
        if (ok &amp;amp;&amp;amp; !item-&amp;gt;text().isEmpty()) {&lt;br /&gt;
            total += value;&lt;br /&gt;
            number++;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (number &amp;gt; 0)&lt;br /&gt;
        tableWidget-&amp;gt;currentItem()-&amp;gt;setText(QString::number(total/number));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::sumItems()&lt;br /&gt;
{&lt;br /&gt;
    QList&amp;lt;QTableWidgetItem *&amp;gt; selected = tableWidget-&amp;gt;selectedItems();&lt;br /&gt;
    QTableWidgetItem *item;&lt;br /&gt;
    int number = 0;&lt;br /&gt;
    double total = 0;&lt;br /&gt;
    foreach (item, selected) {&lt;br /&gt;
        bool ok;&lt;br /&gt;
        double value = item-&amp;gt;text().toDouble(&amp;amp;ok);&lt;br /&gt;
        if (ok &amp;amp;&amp;amp; !item-&amp;gt;text().isEmpty()) {&lt;br /&gt;
            total += value;&lt;br /&gt;
            number++;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (number &amp;gt; 0)&lt;br /&gt;
        tableWidget-&amp;gt;currentItem()-&amp;gt;setText(QString::number(total));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Creates a 3x3 table==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
int main(int argc, char* argv[])&lt;br /&gt;
{&lt;br /&gt;
  QApplication app(argc, argv);&lt;br /&gt;
  QTableWidget tableWidget(3,3);&lt;br /&gt;
  for(introw=0;row&amp;lt;tableWidget.rowCount(); row++)&lt;br /&gt;
    for (int col=0;col&amp;lt;tableWidget.columnCount(); col++)&lt;br /&gt;
      tableWidget.setItem(row,col,new QTableWidgetItem(QString::number(row*col)));&lt;br /&gt;
  tableWidget.show();&lt;br /&gt;
  return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==QTableWidget and QTableWidgetItem==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QTableWidget;&lt;br /&gt;
class QTableWidgetItem;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void averageItems();&lt;br /&gt;
    void sumItems();&lt;br /&gt;
private:&lt;br /&gt;
    void setupTableItems();&lt;br /&gt;
    QAction *removeAction;&lt;br /&gt;
    QTableWidget *tableWidget;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;math.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    QMenu *itemsMenu = new QMenu(tr(&amp;quot;&amp;amp;Items&amp;quot;));&lt;br /&gt;
    QAction *sumItemsAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Sum Items&amp;quot;));&lt;br /&gt;
    QAction *averageItemsAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Average Items&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(itemsMenu);&lt;br /&gt;
    tableWidget = new QTableWidget(12, 3, this);&lt;br /&gt;
    tableWidget-&amp;gt;setSelectionMode(QAbstractItemView::ExtendedSelection);&lt;br /&gt;
    tableWidget-&amp;gt;setDragEnabled(true);&lt;br /&gt;
    tableWidget-&amp;gt;setAcceptDrops(true);&lt;br /&gt;
    tableWidget-&amp;gt;setDropIndicatorShown(true);&lt;br /&gt;
    QTableWidgetItem *valuesHeaderItem = new QTableWidgetItem(tr(&amp;quot;Values&amp;quot;));&lt;br /&gt;
    tableWidget-&amp;gt;setHorizontalHeaderItem(0, valuesHeaderItem);&lt;br /&gt;
    valuesHeaderItem-&amp;gt;setTextAlignment(Qt::AlignVCenter);&lt;br /&gt;
    QTableWidgetItem *squaresHeaderItem = new QTableWidgetItem(tr(&amp;quot;Squares&amp;quot;));&lt;br /&gt;
    squaresHeaderItem-&amp;gt;setIcon(QIcon(QPixmap(&amp;quot;:/Images/squared.png&amp;quot;)));&lt;br /&gt;
    squaresHeaderItem-&amp;gt;setTextAlignment(Qt::AlignVCenter);&lt;br /&gt;
    QTableWidgetItem *cubesHeaderItem = new QTableWidgetItem(tr(&amp;quot;Cubes&amp;quot;));&lt;br /&gt;
    cubesHeaderItem-&amp;gt;setIcon(QIcon(QPixmap(&amp;quot;:/Images/cubed.png&amp;quot;)));&lt;br /&gt;
    cubesHeaderItem-&amp;gt;setTextAlignment(Qt::AlignVCenter);&lt;br /&gt;
    tableWidget-&amp;gt;setHorizontalHeaderItem(1, squaresHeaderItem);&lt;br /&gt;
    tableWidget-&amp;gt;setHorizontalHeaderItem(2, cubesHeaderItem);&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));&lt;br /&gt;
    connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems()));&lt;br /&gt;
    connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems()));&lt;br /&gt;
    setupTableItems();&lt;br /&gt;
    setCentralWidget(tableWidget);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Table Widget&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::setupTableItems()&lt;br /&gt;
{&lt;br /&gt;
    for (int row = 0; row &amp;lt; tableWidget-&amp;gt;rowCount()-1; ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; tableWidget-&amp;gt;columnCount(); ++column) {&lt;br /&gt;
    QTableWidgetItem *newItem = new QTableWidgetItem(tr(&amp;quot;%1&amp;quot;).arg(&lt;br /&gt;
        pow((float)row, (float)column+1)));&lt;br /&gt;
    tableWidget-&amp;gt;setItem(row, column, newItem);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    for (int column = 0; column &amp;lt; tableWidget-&amp;gt;columnCount(); ++column) {&lt;br /&gt;
        QTableWidgetItem *newItem = new QTableWidgetItem;&lt;br /&gt;
        newItem-&amp;gt;setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);&lt;br /&gt;
        tableWidget-&amp;gt;setItem(tableWidget-&amp;gt;rowCount()-1, column, newItem);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::averageItems()&lt;br /&gt;
{&lt;br /&gt;
    QList&amp;lt;QTableWidgetItem *&amp;gt; selected = tableWidget-&amp;gt;selectedItems();&lt;br /&gt;
    QTableWidgetItem *item;&lt;br /&gt;
    int number = 0;&lt;br /&gt;
    double total = 0;&lt;br /&gt;
    foreach (item, selected) {&lt;br /&gt;
        bool ok;&lt;br /&gt;
        double value = item-&amp;gt;text().toDouble(&amp;amp;ok);&lt;br /&gt;
        &lt;br /&gt;
        if (ok &amp;amp;&amp;amp; !item-&amp;gt;text().isEmpty()) {&lt;br /&gt;
            total += value;&lt;br /&gt;
            number++;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (number &amp;gt; 0)&lt;br /&gt;
        tableWidget-&amp;gt;currentItem()-&amp;gt;setText(QString::number(total/number));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::sumItems()&lt;br /&gt;
{&lt;br /&gt;
    QList&amp;lt;QTableWidgetItem *&amp;gt; selected = tableWidget-&amp;gt;selectedItems();&lt;br /&gt;
    QTableWidgetItem *item;&lt;br /&gt;
    int number = 0;&lt;br /&gt;
    double total = 0;&lt;br /&gt;
    foreach (item, selected) {&lt;br /&gt;
        bool ok;&lt;br /&gt;
        double value = item-&amp;gt;text().toDouble(&amp;amp;ok);&lt;br /&gt;
        if (ok &amp;amp;&amp;amp; !item-&amp;gt;text().isEmpty()) {&lt;br /&gt;
            total += value;&lt;br /&gt;
            number++;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (number &amp;gt; 0)&lt;br /&gt;
        tableWidget-&amp;gt;currentItem()-&amp;gt;setText(QString::number(total));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Resize QTableWidget==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QTableWidget;&lt;br /&gt;
class QTableWidgetItem;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void changeHeight();&lt;br /&gt;
    void changeWidth();&lt;br /&gt;
private:&lt;br /&gt;
    void setupTableItems();&lt;br /&gt;
    QTableWidget *tableWidget;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    QMenu *tableMenu = new QMenu(tr(&amp;quot;&amp;amp;Table&amp;quot;));&lt;br /&gt;
    QAction *tableWidthAction = tableMenu-&amp;gt;addAction(tr(&amp;quot;Change Table &amp;amp;Width&amp;quot;));&lt;br /&gt;
    QAction *tableHeightAction = tableMenu-&amp;gt;addAction(tr(&amp;quot;Change Table &amp;amp;Height&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(tableMenu);&lt;br /&gt;
&lt;br /&gt;
    tableWidget = new QTableWidget(this);&lt;br /&gt;
    tableWidget-&amp;gt;setSelectionMode(QAbstractItemView::ExtendedSelection);&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));&lt;br /&gt;
    connect(tableWidthAction, SIGNAL(triggered()), this, SLOT(changeWidth()));&lt;br /&gt;
    connect(tableHeightAction, SIGNAL(triggered()), this, SLOT(changeHeight()));&lt;br /&gt;
    setupTableItems();&lt;br /&gt;
    setCentralWidget(tableWidget);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;Table Widget Resizing&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::setupTableItems()&lt;br /&gt;
{&lt;br /&gt;
    tableWidget-&amp;gt;setRowCount(10);&lt;br /&gt;
    tableWidget-&amp;gt;setColumnCount(5);&lt;br /&gt;
&lt;br /&gt;
    for (int row = 0; row &amp;lt; tableWidget-&amp;gt;rowCount(); ++row) {&lt;br /&gt;
        for (int column = 0; column &amp;lt; tableWidget-&amp;gt;columnCount(); ++column) {&lt;br /&gt;
    QTableWidgetItem *newItem = new QTableWidgetItem(tr(&amp;quot;%1&amp;quot;).arg(&lt;br /&gt;
        (row+1)*(column+1)));&lt;br /&gt;
    tableWidget-&amp;gt;setItem(row, column, newItem);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::changeWidth()&lt;br /&gt;
{&lt;br /&gt;
    bool ok;&lt;br /&gt;
    int newWidth = QInputDialog::getInteger(this, tr(&amp;quot;Change table width&amp;quot;),&lt;br /&gt;
        tr(&amp;quot;Input the number of columns required (1-20):&amp;quot;),&lt;br /&gt;
        tableWidget-&amp;gt;columnCount(), 1, 20, 1, &amp;amp;ok);&lt;br /&gt;
    if (ok)&lt;br /&gt;
        tableWidget-&amp;gt;setColumnCount(newWidth);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::changeHeight()&lt;br /&gt;
{&lt;br /&gt;
    bool ok;&lt;br /&gt;
    int newHeight = QInputDialog::getInteger(this, tr(&amp;quot;Change table height&amp;quot;),&lt;br /&gt;
        tr(&amp;quot;Input the number of rows required (1-20):&amp;quot;),&lt;br /&gt;
        tableWidget-&amp;gt;rowCount(), 1, 20, 1, &amp;amp;ok);&lt;br /&gt;
    if (ok)&lt;br /&gt;
        tableWidget-&amp;gt;setRowCount(newHeight);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>