mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-03 15:55:27 +08:00
qt 6.5.1 original
This commit is contained in:
49
examples/widgets/itemviews/frozencolumn/CMakeLists.txt
Normal file
49
examples/widgets/itemviews/frozencolumn/CMakeLists.txt
Normal file
@ -0,0 +1,49 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(frozencolumn LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/frozencolumn")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(frozencolumn
|
||||
freezetablewidget.cpp freezetablewidget.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(frozencolumn PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(frozencolumn PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
# Resources:
|
||||
set(grades_resource_files
|
||||
"grades.txt"
|
||||
)
|
||||
|
||||
qt_add_resources(frozencolumn "grades"
|
||||
PREFIX
|
||||
"/"
|
||||
FILES
|
||||
${grades_resource_files}
|
||||
)
|
||||
|
||||
install(TARGETS frozencolumn
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
126
examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp
Normal file
126
examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "freezetablewidget.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
#include <QHeaderView>
|
||||
|
||||
//! [constructor]
|
||||
FreezeTableWidget::FreezeTableWidget(QAbstractItemModel * model)
|
||||
{
|
||||
setModel(model);
|
||||
frozenTableView = new QTableView(this);
|
||||
|
||||
init();
|
||||
|
||||
//connect the headers and scrollbars of both tableviews together
|
||||
connect(horizontalHeader(),&QHeaderView::sectionResized, this,
|
||||
&FreezeTableWidget::updateSectionWidth);
|
||||
connect(verticalHeader(),&QHeaderView::sectionResized, this,
|
||||
&FreezeTableWidget::updateSectionHeight);
|
||||
|
||||
connect(frozenTableView->verticalScrollBar(), &QAbstractSlider::valueChanged,
|
||||
verticalScrollBar(), &QAbstractSlider::setValue);
|
||||
connect(verticalScrollBar(), &QAbstractSlider::valueChanged,
|
||||
frozenTableView->verticalScrollBar(), &QAbstractSlider::setValue);
|
||||
|
||||
|
||||
}
|
||||
//! [constructor]
|
||||
|
||||
FreezeTableWidget::~FreezeTableWidget()
|
||||
{
|
||||
delete frozenTableView;
|
||||
}
|
||||
|
||||
//! [init part1]
|
||||
void FreezeTableWidget::init()
|
||||
{
|
||||
frozenTableView->setModel(model());
|
||||
frozenTableView->setFocusPolicy(Qt::NoFocus);
|
||||
frozenTableView->verticalHeader()->hide();
|
||||
frozenTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
|
||||
viewport()->stackUnder(frozenTableView);
|
||||
//! [init part1]
|
||||
|
||||
//! [init part2]
|
||||
frozenTableView->setStyleSheet("QTableView { border: none;"
|
||||
"background-color: #8EDE21;"
|
||||
"selection-background-color: #999}"); //for demo purposes
|
||||
frozenTableView->setSelectionModel(selectionModel());
|
||||
for (int col = 1; col < model()->columnCount(); ++col)
|
||||
frozenTableView->setColumnHidden(col, true);
|
||||
|
||||
frozenTableView->setColumnWidth(0, columnWidth(0) );
|
||||
|
||||
frozenTableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
frozenTableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
frozenTableView->show();
|
||||
|
||||
updateFrozenTableGeometry();
|
||||
|
||||
setHorizontalScrollMode(ScrollPerPixel);
|
||||
setVerticalScrollMode(ScrollPerPixel);
|
||||
frozenTableView->setVerticalScrollMode(ScrollPerPixel);
|
||||
}
|
||||
//! [init part2]
|
||||
|
||||
|
||||
//! [sections]
|
||||
void FreezeTableWidget::updateSectionWidth(int logicalIndex, int /* oldSize */, int newSize)
|
||||
{
|
||||
if (logicalIndex == 0){
|
||||
frozenTableView->setColumnWidth(0, newSize);
|
||||
updateFrozenTableGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
void FreezeTableWidget::updateSectionHeight(int logicalIndex, int /* oldSize */, int newSize)
|
||||
{
|
||||
frozenTableView->setRowHeight(logicalIndex, newSize);
|
||||
}
|
||||
//! [sections]
|
||||
|
||||
|
||||
//! [resize]
|
||||
void FreezeTableWidget::resizeEvent(QResizeEvent * event)
|
||||
{
|
||||
QTableView::resizeEvent(event);
|
||||
updateFrozenTableGeometry();
|
||||
}
|
||||
//! [resize]
|
||||
|
||||
|
||||
//! [navigate]
|
||||
QModelIndex FreezeTableWidget::moveCursor(CursorAction cursorAction,
|
||||
Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
QModelIndex current = QTableView::moveCursor(cursorAction, modifiers);
|
||||
|
||||
if (cursorAction == MoveLeft && current.column() > 0
|
||||
&& visualRect(current).topLeft().x() < frozenTableView->columnWidth(0) ){
|
||||
const int newValue = horizontalScrollBar()->value() + visualRect(current).topLeft().x()
|
||||
- frozenTableView->columnWidth(0);
|
||||
horizontalScrollBar()->setValue(newValue);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
//! [navigate]
|
||||
|
||||
void FreezeTableWidget::scrollTo (const QModelIndex & index, ScrollHint hint){
|
||||
if (index.column() > 0)
|
||||
QTableView::scrollTo(index, hint);
|
||||
}
|
||||
|
||||
//! [geometry]
|
||||
void FreezeTableWidget::updateFrozenTableGeometry()
|
||||
{
|
||||
frozenTableView->setGeometry(verticalHeader()->width() + frameWidth(),
|
||||
frameWidth(), columnWidth(0),
|
||||
viewport()->height()+horizontalHeader()->height());
|
||||
}
|
||||
//! [geometry]
|
||||
|
||||
|
35
examples/widgets/itemviews/frozencolumn/freezetablewidget.h
Normal file
35
examples/widgets/itemviews/frozencolumn/freezetablewidget.h
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#ifndef FREEZETABLEWIDGET_H
|
||||
#define FREEZETABLEWIDGET_H
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
//! [Widget definition]
|
||||
class FreezeTableWidget : public QTableView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FreezeTableWidget(QAbstractItemModel * model);
|
||||
~FreezeTableWidget();
|
||||
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
|
||||
void scrollTo (const QModelIndex & index, ScrollHint hint = EnsureVisible) override;
|
||||
|
||||
private:
|
||||
QTableView *frozenTableView;
|
||||
void init();
|
||||
void updateFrozenTableGeometry();
|
||||
|
||||
|
||||
private slots:
|
||||
void updateSectionWidth(int logicalIndex, int oldSize, int newSize);
|
||||
void updateSectionHeight(int logicalIndex, int oldSize, int newSize);
|
||||
|
||||
};
|
||||
//! [Widget definition]
|
||||
#endif // FREEZETABLEWIDGET_H
|
11
examples/widgets/itemviews/frozencolumn/frozencolumn.pro
Normal file
11
examples/widgets/itemviews/frozencolumn/frozencolumn.pro
Normal file
@ -0,0 +1,11 @@
|
||||
QT += widgets
|
||||
requires(qtConfig(tableview))
|
||||
|
||||
HEADERS += freezetablewidget.h
|
||||
SOURCES += main.cpp freezetablewidget.cpp
|
||||
RESOURCES += grades.qrc
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/frozencolumn
|
||||
INSTALLS += target
|
||||
|
5
examples/widgets/itemviews/frozencolumn/grades.qrc
Normal file
5
examples/widgets/itemviews/frozencolumn/grades.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>grades.txt</file>
|
||||
</qresource>
|
||||
</RCC>
|
36
examples/widgets/itemviews/frozencolumn/grades.txt
Normal file
36
examples/widgets/itemviews/frozencolumn/grades.txt
Normal file
@ -0,0 +1,36 @@
|
||||
France , Norway , YDS , UK(tech.), UK(adj.) , UIAA , Ger , Australia , Finland , Brazil
|
||||
|
||||
1, , 5.2, , , I , I , , , Isup
|
||||
2, , 5.3, , , II , II , 11, , II
|
||||
3, 3, 5.4, , , III , III , 12, , IIsup
|
||||
4, 4, 5.5, 4a , VD , IV , IV , 12, , III
|
||||
5a , 5-, 5.6, , S , V- , V , 13, 5-, IIIsup
|
||||
5b , 5, 5.7, 4b , HS , V , VI , 14, 5, IV
|
||||
, , , 4c , , V+ , , 15, ,
|
||||
5c , 5+, 5.8, , VS , VI- , VIIa , 16, 5, IVsup
|
||||
6a , 6-, 5.9, 5a , HVS , VI , VIIb , 17, , V
|
||||
6a+ , 6-/6 , 5.10a , , E1 , VI+ , VIIc , 18, 6-, VI
|
||||
6b , , 5.10b , 5b , , , , 19, , VI/VI+
|
||||
6b+ , 6, 5.10c , , E2 , VII- , VIIIa , 20, 6, VIsup/VI+
|
||||
6c , 6+, 5.10d , 5c , , VII , VIIIb , 21, , VIsup
|
||||
6c+ , 7-, 5.11a , , E3 , VII+ , VIIIc , 22, 6, 7a
|
||||
6c+ , 7, 5.11b , , , , , 23, , 7b
|
||||
7a , 7+, 5.11c , 6a , E4 , VIII- , IXa , 24, 7-, 7c
|
||||
7a , 7+/8- , 5.11d , , , VIII , IXb , , , 7c
|
||||
7a+ , 8-, 5.12a , , E5 , VIII+ , IXc , 25, 7, 8a
|
||||
7b , 8, 5.12b , 6b , , , , 26, 8-, 8b
|
||||
7b+ , 8/8+ , 5.12c , , E6 , IX- , Xa , 27, 8, 8c
|
||||
7c , 8+, 5.12d , 6c , , IX , Xb , 28, 8, 9a
|
||||
7c+ , 9-, 5.13a , , E7 , IX+ , Xc , 29, 9-, 9b
|
||||
8a , , 5.13b , , , , , , 9, 9c
|
||||
8a+ , 9-/9 , 5.13c , 7a , , X- , , 30, 9, 10a
|
||||
8b , 9, 5.13d , , E8 , X , , 31, 10-, 10b
|
||||
8b+ , 9/9+ , 5.14a , , , X+ , , 32, 10, 10c
|
||||
8c , 9+, 5.14b , 7b , , , , 33, 10, 11a
|
||||
8c+ , 10-, 5.14c , , E9 , XI- , , 34, 11-, 11b
|
||||
9a , 10, 5.14d , 7c , , XI , , 35, 11, 11c
|
||||
9a+ , , 5.15a , , , XI+ , , , , 12a
|
||||
9b , , 5.15b , , , , , , , 12b
|
||||
|
||||
# Wikipedia contributors. Grade (climbing). Wikipedia, The Free Encyclopedia. May 15, 2009, 20:42 UTC.
|
||||
# Available at: http://en.wikipedia.org/w/index.php?title=Grade_(climbing)&oldid=290165724. Accessed May 28, 2009.
|
49
examples/widgets/itemviews/frozencolumn/main.cpp
Normal file
49
examples/widgets/itemviews/frozencolumn/main.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStandardItemModel>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#include "freezetablewidget.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Q_INIT_RESOURCE(grades);
|
||||
|
||||
QApplication app( argc, argv );
|
||||
QStandardItemModel *model=new QStandardItemModel();
|
||||
|
||||
QFile file(":/grades.txt");
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QTextStream stream(&file);
|
||||
|
||||
QString line = stream.readLine();
|
||||
QStringList list = line.simplified().split(',');
|
||||
model->setHorizontalHeaderLabels(list);
|
||||
|
||||
int row = 0;
|
||||
QStandardItem *newItem = nullptr;
|
||||
while (!stream.atEnd()) {
|
||||
line = stream.readLine();
|
||||
if (!line.startsWith('#') && line.contains(',')) {
|
||||
list = line.simplified().split(',');
|
||||
for (int col = 0; col < list.length(); ++col){
|
||||
newItem = new QStandardItem(list.at(col));
|
||||
model->setItem(row, col, newItem);
|
||||
}
|
||||
++row;
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
FreezeTableWidget *tableView = new FreezeTableWidget(model);
|
||||
|
||||
tableView->setWindowTitle(QObject::tr("Frozen Column Example"));
|
||||
tableView->resize(560, 680);
|
||||
tableView->show();
|
||||
return app.exec();
|
||||
}
|
||||
|
Reference in New Issue
Block a user