0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the documentation of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtGui>
|
|
43 |
|
|
44 |
#include "mainwindow.h"
|
|
45 |
|
|
46 |
MainWindow::MainWindow()
|
|
47 |
{
|
|
48 |
QMenu *fileMenu = new QMenu(tr("&File"));
|
|
49 |
|
|
50 |
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
|
|
51 |
quitAction->setShortcut(tr("Ctrl+Q"));
|
|
52 |
|
|
53 |
QMenu *tableMenu = new QMenu(tr("&Table"));
|
|
54 |
|
|
55 |
QAction *tableWidthAction = tableMenu->addAction(tr("Change Table &Width"));
|
|
56 |
QAction *tableHeightAction = tableMenu->addAction(tr("Change Table &Height"));
|
|
57 |
|
|
58 |
menuBar()->addMenu(fileMenu);
|
|
59 |
menuBar()->addMenu(tableMenu);
|
|
60 |
|
|
61 |
//! [0]
|
|
62 |
tableWidget = new QTableWidget(this);
|
|
63 |
//! [0]
|
|
64 |
tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
65 |
|
|
66 |
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
|
|
67 |
connect(tableWidthAction, SIGNAL(triggered()), this, SLOT(changeWidth()));
|
|
68 |
connect(tableHeightAction, SIGNAL(triggered()), this, SLOT(changeHeight()));
|
|
69 |
|
|
70 |
setupTableItems();
|
|
71 |
|
|
72 |
setCentralWidget(tableWidget);
|
|
73 |
setWindowTitle(tr("Table Widget Resizing"));
|
|
74 |
}
|
|
75 |
|
|
76 |
void MainWindow::setupTableItems()
|
|
77 |
{
|
|
78 |
//! [1]
|
|
79 |
tableWidget->setRowCount(10);
|
|
80 |
tableWidget->setColumnCount(5);
|
|
81 |
//! [1]
|
|
82 |
|
|
83 |
for (int row = 0; row < tableWidget->rowCount(); ++row) {
|
|
84 |
for (int column = 0; column < tableWidget->columnCount(); ++column) {
|
|
85 |
//! [2]
|
|
86 |
QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(
|
|
87 |
(row+1)*(column+1)));
|
|
88 |
tableWidget->setItem(row, column, newItem);
|
|
89 |
//! [2]
|
|
90 |
}
|
|
91 |
}
|
|
92 |
}
|
|
93 |
|
|
94 |
void MainWindow::changeWidth()
|
|
95 |
{
|
|
96 |
bool ok;
|
|
97 |
|
|
98 |
int newWidth = QInputDialog::getInteger(this, tr("Change table width"),
|
|
99 |
tr("Input the number of columns required (1-20):"),
|
|
100 |
tableWidget->columnCount(), 1, 20, 1, &ok);
|
|
101 |
|
|
102 |
if (ok)
|
|
103 |
tableWidget->setColumnCount(newWidth);
|
|
104 |
}
|
|
105 |
|
|
106 |
void MainWindow::changeHeight()
|
|
107 |
{
|
|
108 |
bool ok;
|
|
109 |
|
|
110 |
int newHeight = QInputDialog::getInteger(this, tr("Change table height"),
|
|
111 |
tr("Input the number of rows required (1-20):"),
|
|
112 |
tableWidget->rowCount(), 1, 20, 1, &ok);
|
|
113 |
|
|
114 |
if (ok)
|
|
115 |
tableWidget->setRowCount(newHeight);
|
|
116 |
}
|