本文整理汇总了C++中QTableView::setSelectionMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setSelectionMode方法的具体用法?C++ QTableView::setSelectionMode怎么用?C++ QTableView::setSelectionMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::setSelectionMode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setModel
void ReceiveCoinsDialog::setModel(WalletModel *model)
{
this->model = model;
if(model && model->getOptionsModel())
{
model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
updateDisplayUnit();
QTableView* tableView = ui->recentRequestsView;
tableView->verticalHeader()->hide();
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tableView->setModel(model->getRecentRequestsTableModel());
tableView->setAlternatingRowColors(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH);
}
示例2: createSongsTable
void MainWindow::createSongsTable(int size)
{
QTableView * songs = ui->tvSongs;
delete songs->model();
delete songs->selectionModel();
QStandardItemModel *model = new QStandardItemModel(size, 3, songs);
QItemSelectionModel *selections = new QItemSelectionModel(model);
songs->setModel(model);
songs->setSelectionModel(selections);
songs->horizontalHeader()->setSectionsMovable(true);
songs->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
songs->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
songs->verticalHeader()->setSectionsMovable(false);
songs->verticalHeader()->setVisible(false);
songs->setSelectionBehavior( QAbstractItemView::SelectRows );
songs->setSelectionMode( QAbstractItemView::SingleSelection );
songs->setContextMenuPolicy(Qt::CustomContextMenu);
// Set StaticContents to enable minimal repaints on resizes.
songs->viewport()->setAttribute(Qt::WA_StaticContents);
model->setHorizontalHeaderItem(0, new QStandardItem(tr("Artist")));
model->setHorizontalHeaderItem(1, new QStandardItem(tr("Title")));
model->setHorizontalHeaderItem(2, new QStandardItem(tr("Length")));
}
示例3: main
int main( int argc, char **argv )
{
QApplication app( argc, argv );
QTreeView *tree = new QTreeView();
QListView *list = new QListView();
QTableView *table = new QTableView();
QSplitter splitter;
splitter.addWidget(tree);
splitter.addWidget(list);
splitter.addWidget(table);
QStandardItemModel model( 5, 2 );
for( int r=0; r<5; r++ )
{
for( int c=0; c<2; c++)
{
QStandardItem *item = new QStandardItem(QString("Row:%0, Column:%1").arg(r).arg(c));
if(c == 0)
{
for(int i=0; i<3; i++)
{
QStandardItem *child = new QStandardItem(QString("Item %0").arg(i));
child->setEditable(false);
item->appendRow(child);
}
}
model.setItem(r, c, item);
}
}
model.setHorizontalHeaderItem(0, new QStandardItem("Foo"));
model.setHorizontalHeaderItem(1, new QStandardItem("Bar-Baz"));
tree->setModel(&model);
list->setModel(&model);
table->setModel(&model);
list->setSelectionModel(tree->selectionModel());
table->setSelectionModel(tree->selectionModel());
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setSelectionMode(QAbstractItemView::SingleSelection);
splitter.show();
MainWindow w;
w.show();
return app.exec();
}
示例4: MakeTableView
// Table factory
QTableView* MakeTableView(QAbstractItemModel* model, bool sortingEnabled = true, uint32_t modelSortColumn = 0)
{
class MyTable : public QTableView
{
public:
QStyleOptionViewItem viewOptions() const override
{
QStyleOptionViewItem option = QTableView::viewOptions();
option.decorationAlignment = Qt::AlignHCenter | Qt::AlignCenter;
option.decorationPosition = QStyleOptionViewItem::Top;
return option;
}
void mouseMoveEvent(QMouseEvent* event) override
{
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
QVariant data = model()->data(index, PlayerTableModel::CursorRole);
Qt::CursorShape shape = Qt::ArrowCursor;
if (!data.isNull()) {
shape = Qt::CursorShape(data.toInt());
}
setCursor(shape);
}
QTableView::mouseMoveEvent(event);
}
};
QTableView* tableView = new MyTable();
tableView->setModel(model);
tableView->setSortingEnabled(sortingEnabled);
if (sortingEnabled) {
tableView->sortByColumn(FindColumn(model, modelSortColumn));
}
tableView->verticalHeader()->hide();
tableView->setAlternatingRowColors(true);
tableView->verticalHeader()->setDefaultSectionSize(15);
tableView->resizeColumnsToContents();
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->setFocusPolicy(Qt::StrongFocus);
// enable mouse tracking
tableView->setMouseTracking(true);
tableView->viewport()->setMouseTracking(true);
tableView->installEventFilter(this);
tableView->viewport()->installEventFilter(this);
return tableView;
}
示例5: on_pbPosition_clicked
void SettingsDialog::on_pbPosition_clicked()
{
QScopedPointer< Gui::Dialog > dialog(new Gui::Dialog(Gui::Dialog::CenterOfScreen,this));
PositionModel *model = new PositionModel(dialog.data());
QTableView *view = new QTableView(dialog.data());
QItemSelectionModel *selectionModel = new QItemSelectionModel(model,dialog.data());
dialog->setWindowTitle(tr("Set position"));
QVBoxLayout *layout = new QVBoxLayout;
QDialogButtonBox *dialogButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
Qt::Horizontal,dialog.data());
connect(dialogButtons,SIGNAL(accepted()),dialog.data(),SLOT(accept()));
connect(dialogButtons,SIGNAL(rejected()),dialog.data(),SLOT(reject()));
view->setModel(model);
view->setItemDelegateForColumn(0,new PositionLabelDelegate);
view->setItemDelegateForColumn(1,new PositionDelegate(QApplication::palette()));
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionModel(selectionModel);
view->verticalHeader()->setVisible(false);
view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
layout->addWidget(view);
layout->addWidget(dialogButtons);
dialog->setLayout(layout);
dialog->resize(700,500);
connect(dialog.data(),SIGNAL(executed()),view,SLOT(resizeColumnsToContents()));
connect(dialog.data(),SIGNAL(executed()),view,SLOT(resizeRowsToContents()));
selectionModel->select(model->index(pbPosition->property("wallPosition").toInt(),0),
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
view->scrollTo(model->index(pbPosition->property("wallPosition").toInt(),0));
if (dialog->exec() == QDialog::Accepted)
{
Wally::Application::Position p = static_cast<Wally::Application::Position> (selectionModel->currentIndex().row());
pbPosition->setProperty("wallPosition",static_cast<int> (p));
pbPosition->setText(positionToString(p).replace("&","&&"));
settingsModified();
}
}
示例6: QDialog
QmitkModulesDialog::QmitkModulesDialog(QWidget *parent, Qt::WindowFlags f) :
QDialog(parent, f)
{
this->setWindowTitle("MITK Modules");
QVBoxLayout* layout = new QVBoxLayout();
this->setLayout(layout);
QTableView* tableView = new QTableView(this);
QmitkModuleTableModel* tableModel = new QmitkModuleTableModel(tableView);
QSortFilterProxyModel* sortProxyModel = new QSortFilterProxyModel(tableView);
sortProxyModel->setSourceModel(tableModel);
sortProxyModel->setDynamicSortFilter(true);
tableView->setModel(sortProxyModel);
tableView->verticalHeader()->hide();
tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
tableView->setTextElideMode(Qt::ElideMiddle);
tableView->setSortingEnabled(true);
tableView->sortByColumn(0, Qt::AscendingOrder);
tableView->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->horizontalHeader()->setCascadingSectionResizes(true);
layout->addWidget(tableView);
QDialogButtonBox* btnBox = new QDialogButtonBox(QDialogButtonBox::Close);
layout->addWidget(btnBox);
this->resize(800, 600);
connect(btnBox, SIGNAL(rejected()), this, SLOT(reject()));
}
示例7: setModel
void ReceiveCoinsDialog::setModel(WalletModel *_model)
{
this->model = _model;
if(_model && _model->getOptionsModel())
{
_model->getRecentRequestsTableModel()->sort(RecentRequestsTableModel::Date, Qt::DescendingOrder);
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
updateDisplayUnit();
QTableView* tableView = ui->recentRequestsView;
tableView->verticalHeader()->hide();
tableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tableView->setModel(_model->getRecentRequestsTableModel());
tableView->setAlternatingRowColors(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::ContiguousSelection);
tableView->setColumnWidth(RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
tableView->setColumnWidth(RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this,
SLOT(recentRequestsView_selectionChanged(QItemSelection, QItemSelection)));
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);
if (model->wallet().getDefaultAddressType() == OutputType::BECH32) {
ui->useBech32->setCheckState(Qt::Checked);
} else {
ui->useBech32->setCheckState(Qt::Unchecked);
}
// eventually disable the main receive button if private key operations are disabled
ui->receiveButton->setEnabled(!model->privateKeysDisabled());
}
示例8: getSpeciesList
bool DatabaseHandler::getSpeciesList(QString type, QComboBox * cmb_box) {
qDebug() << "Populating species list for " << type;
QString qstr = "SELECT name_de, name_lat, euring_id, length FROM taxa LEFT JOIN "
"(SELECT id_code, to_char(avg(length), 'FM99.99') as length FROM census WHERE tp='%1' GROUP BY id_code) as lt ON taxa.euring_id = lt.id_code "
"WHERE type='%1' ORDER BY seaflag DESC, name_de";
QSqlQueryModel * model = new QSqlQueryModel;
model->setQuery(qstr.arg(type));
qDebug() << qstr.arg(type);
model->setHeaderData(0, Qt::Horizontal, "Deutscher Name");
model->setHeaderData(1, Qt::Horizontal, "Wissenschaftlicher Name");
model->setHeaderData(2, Qt::Horizontal, "EURING Code");
model->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("Länge"));
cmb_box->setModel(model);
QTableView * view = new QTableView;
cmb_box->setView(view);
view->verticalHeader()->hide();
view->hideColumn(2);
view->resizeColumnsToContents();
view->setSelectionMode(QAbstractItemView::SingleSelection);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setMinimumWidth(view->horizontalHeader()->length());
return true;
}
示例9: QWidget
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
resize(400,300);
if(connect())
{
QTableView *view = new QTableView(this);
QSqlRelationalTableModel *model = new QSqlRelationalTableModel;//要先有数据才能创建model,也就是先连接数据库局
view->setGeometry(0,0,400,300);
view->setModel(model);
model->setTable("student");
model->setSort(0,Qt::AscendingOrder);
// model->setHeaderData(0,Qt::Horizontal,"Name");//from 0
// model->setHeaderData(1,Qt::Horizontal,"Age");
// model->setHeaderData(2,Qt::Horizontal,"likes");
model->setRelation(3,QSqlRelation("city","id","name"));
model->select();
// view->setModel(model);
view->setSelectionMode(QAbstractItemView::SingleSelection);//设置选择模式
view->setSelectionBehavior(QAbstractItemView::SelectRows);//选择行
// view->resizeColumnsToContents();//tiaozhengziti
view->setEditTriggers(QAbstractItemView::DoubleClicked);//不可编辑?
QHeaderView *header = view->horizontalHeader();
header->setStretchLastSection(true);
view->setItemDelegate(new QSqlRelationalDelegate(view));
// QHeaderView *head = view->verticalHeader();
// head->setStretchLastSection(true);
// view->show();
// this?->show();
}
}
示例10: QWidget
//.........这里部分代码省略.........
pageTacheComposite->setLayout(layoutCreationEvent);
//imbrication onglets niveau2 + layout principal pageSaisie
ongletsNiveau2->addTab(pageCreationprojet, "Projet");
ongletsNiveau2->addTab(pageTacheUnitaire, "Tâche unitaire");
ongletsNiveau2->addTab(pageTacheComposite, "Tâche composite");
layoutPageSaisiePrincipal->addWidget(gBProjetTV);
layoutPageSaisiePrincipal->addWidget(supportOngletsCreation);
//page Affichage/////////////////////////////////////////////////////////////////////////////////////////////////////
layoutPageAffichagePrincipal = new QVBoxLayout;
//En tete (gestion semaine suivante/precedente
layoutHautAgenda = new QHBoxLayout;
dateReferenceAgenda = new QDate(QDate::currentDate());
jourActuel = new QPushButton(constructionMessageSemaineAgenda(dateReferenceAgenda));
jourActuel->setEnabled(false);
bSemainePrecedente = new QPushButton("Semaine precedent");
bSemaineSuivante = new QPushButton("Semaine suivant");
layoutHautAgenda->addWidget(bSemainePrecedente);
layoutHautAgenda->addWidget(jourActuel);
layoutHautAgenda->addWidget(bSemaineSuivante);
QStandardItemModel *modelAgenda = new QStandardItemModel(60, 7);
QTableView *vueAgenda = new QTableView;
vueAgenda->setEditTriggers(QAbstractItemView::NoEditTriggers);
vueAgenda->setModel(modelAgenda);
vueAgenda->setFixedWidth(1157);
vueAgenda->setFixedHeight(625);
vueAgenda->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
vueAgenda->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
vueAgenda->setSelectionMode(QAbstractItemView::SingleSelection);
//===========
vueAgenda->setGridStyle(Qt::DashDotLine);
miseAJourTableau(*modelAgenda); //, *vueAgenda);
itemCol0 = new QStandardItem(chaineJoursHeader(1, dateReferenceAgenda->addDays(1-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
itemCol1 = new QStandardItem(chaineJoursHeader(2, dateReferenceAgenda->addDays(2-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
itemCol2 = new QStandardItem(chaineJoursHeader(3, dateReferenceAgenda->addDays(3-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
itemCol3 = new QStandardItem(chaineJoursHeader(4, dateReferenceAgenda->addDays(4-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
itemCol4 = new QStandardItem(chaineJoursHeader(5, dateReferenceAgenda->addDays(5-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
itemCol5 = new QStandardItem(chaineJoursHeader(6, dateReferenceAgenda->addDays(6-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
itemCol6 = new QStandardItem(chaineJoursHeader(7, dateReferenceAgenda->addDays(7-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month()));
modelAgenda->setHorizontalHeaderItem(0, itemCol0);
modelAgenda->setHorizontalHeaderItem(1, itemCol1);
modelAgenda->setHorizontalHeaderItem(2, itemCol2);
modelAgenda->setHorizontalHeaderItem(3, itemCol3);
modelAgenda->setHorizontalHeaderItem(4, itemCol4);
modelAgenda->setHorizontalHeaderItem(5, itemCol5);
modelAgenda->setHorizontalHeaderItem(6, itemCol6);
QStringList headerVTableau;
for(unsigned int i=7; i<22; i++)
{
headerVTableau << QString::number(i)+"h00";
for(unsigned int j=1; j<4; j++)
{
headerVTableau << "";
//headerVTableau << QString::number(j*15);
}
}
示例11: printTable
void PrintLayout::printTable()
{
// create and setup a table
QTableView table;
table.setAttribute(Qt::WA_DontShowOnScreen);
table.setSelectionMode(QAbstractItemView::NoSelection);
table.setFocusPolicy(Qt::NoFocus);
table.horizontalHeader()->setVisible(false);
table.horizontalHeader()->setResizeMode(QHeaderView::Fixed);
table.verticalHeader()->setVisible(false);
table.verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// fit table to one page initially
table.resize(scaledPageW, scaledPageH);
// create and fill a table model
TablePrintModel model;
struct dive *dive;
int i, row = 0;
addTablePrintHeadingRow(&model, row); // add one heading row
row++;
for_each_dive(i, dive) {
if (!dive->selected && printOptions->print_selected)
continue;
addTablePrintDataRow(&model, row, dive);
row++;
}
table.setModel(&model); // set model to table
// resize columns to percentages from page width
for (int i = 0; i < model.columns; i++) {
int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100);
table.horizontalHeader()->resizeSection(i, pw);
}
// reset the model at this point
model.callReset();
// a list of vertical offsets where pages begin and some helpers
QList<unsigned int> pageIndexes;
pageIndexes.append(0);
int tableHeight = 0, rowH = 0, accH = 0;
// process all rows
for (int i = 0; i < model.rows; i++) {
rowH = table.rowHeight(i);
accH += rowH;
if (accH > scaledPageH) { // push a new page index and add a heading
pageIndexes.append(pageIndexes.last() + (accH - rowH));
addTablePrintHeadingRow(&model, i);
accH = 0;
i--;
}
tableHeight += rowH;
}
pageIndexes.append(pageIndexes.last() + accH);
// resize the whole widget so that it can be rendered
table.resize(scaledPageW, tableHeight);
// attach a painter and render pages by using pageIndexes
QPainter painter(printer);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.scale(scaleX, scaleY);
for (int i = 0; i < pageIndexes.size() - 1; i++) {
if (i > 0)
printer->newPage();
QRegion region(0, pageIndexes.at(i) - 1,
table.width(),
pageIndexes.at(i + 1) - pageIndexes.at(i) + 2);
table.render(&painter, QPoint(0, 0), region);
}
}
示例12: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// ![0]
QStandardItemModel model(0, 1);
populateListModel(&model);
// ![0]
QWidget toplevel;
QVBoxLayout *layout = new QVBoxLayout(&toplevel);
// ![1]
QMaemo5ValueButton *button1 = new QMaemo5ValueButton("Value besides text");
button1->setValueLayout(QMaemo5ValueButton::ValueBesideText);
QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector;
selector1->setModel(&model);
// not setting the current index means that the value is empty.
button1->setPickSelector(selector1);
// ![1]
// ![2]
QStandardItemModel tableModel(0, 0);
populateTableModel(&tableModel);
// ![2]
// ![3]
QMaemo5ValueButton *button2 = new QMaemo5ValueButton("Value under text");
button2->setValueLayout(QMaemo5ValueButton::ValueUnderText);
QMaemo5ListPickSelector *selector2 = new QMaemo5ListPickSelector;
selector2->setModel(&tableModel);
selector2->setModelColumn(2);
selector2->setCurrentIndex(5);
button2->setPickSelector(selector2);
// ![3]
// create a custom view we want a table view instead of a list
QTableView *view = new QTableView();
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
// try to get a sensible column width and row height
view->setModel(&tableModel); // set the model in order to get correct column widths
view->resizeColumnsToContents();
view->resizeRowsToContents();
view->horizontalHeader()->setStretchLastSection(true);
view->verticalHeader()->setVisible(false);
view->horizontalHeader()->setVisible(false);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->setSelectionMode(QAbstractItemView::SingleSelection);
// five rows should be visible as a default
if (view->verticalHeader()->sectionSize(0)>0)
view->setMinimumHeight(view->verticalHeader()->sectionSize(0) * 5);
QMaemo5ValueButton *button3 = new QMaemo5ValueButton("Value centered under text");
button3->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered);
QMaemo5ListPickSelector *selector3 = new QMaemo5ListPickSelector;
selector3->setModel(&tableModel);
selector3->setModelColumn(2);
selector3->setView(view); // set our new custom view
selector3->setCurrentIndex(0);
button3->setPickSelector(selector3);
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
toplevel.show();
return app.exec();
}
示例13: printTable
void PrintLayout::printTable()
{
struct dive *dive;
int done = 0; // percents done
int i, row = 0, progress, total = estimateTotalDives();
if (!total)
return;
// create and setup a table
QTableView table;
table.setAttribute(Qt::WA_DontShowOnScreen);
table.setSelectionMode(QAbstractItemView::NoSelection);
table.setFocusPolicy(Qt::NoFocus);
table.horizontalHeader()->setVisible(false);
table.verticalHeader()->setVisible(false);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
table.horizontalHeader()->setResizeMode(QHeaderView::Fixed);
table.verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
#else
table.horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
table.verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
#endif
table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// fit table to one page initially
table.resize(scaledPageW, scaledPageH);
// don't show border
table.setStyleSheet(
"QTableView { border: none }");
// create and fill a table model
TablePrintModel model;
addTablePrintHeadingRow(&model, row); // add one heading row
row++;
progress = 0;
for_each_dive(i, dive) {
if (!dive->selected && printOptions->print_selected)
continue;
addTablePrintDataRow(&model, row, dive);
row++;
progress++;
emit signalProgress((progress * 10) / total);
}
done = 10;
table.setModel(&model); // set model to table
// resize columns to percentages from page width
int accW = 0;
int cols = model.columns;
int tableW = table.width();
for (i = 0; i < model.columns; i++) {
int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100.0);
accW += pw;
if (i == cols - 1 && accW > tableW) /* adjust last column */
pw -= accW - tableW;
table.horizontalHeader()->resizeSection(i, pw);
}
// reset the model at this point
model.callReset();
// a list of vertical offsets where pages begin and some helpers
QList<unsigned int> pageIndexes;
pageIndexes.append(0);
/* the algorithm bellow processes the table rows in multiple passes,
* compensating for loss of space due to moving rows on a new page instead
* of truncating them.
* there is a 'passes' array defining how much percents of the total
* progress each will take. given, the first and last stage of this function
* use 10% each, then the sum of passes[] here should be 80%.
* two should be enough! */
const int passes[] = { 70, 10 };
int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings;
bool isHeading = false;
for (unsigned int pass = 0; pass < sizeof(passes) / sizeof(passes[0]); pass++) {
progress = headings = accH = 0;
total = model.rows - lastAccIndex;
for (i = lastAccIndex; i < model.rows; i++) {
rowH = table.rowHeight(i);
accH += rowH;
if (isHeading) {
headings += rowH;
isHeading = false;
}
if (accH > scaledPageH) {
lastAccIndex = i;
pageIndexes.append(pageIndexes.last() + (accH - rowH));
addTablePrintHeadingRow(&model, i);
isHeading = true;
accH = 0;
i--;
}
tableHeight += table.rowHeight(i);
progress++;
emit signalProgress(done + (progress * passes[pass]) / total);
}
done += passes[pass];
}
done = 90;
//.........这里部分代码省略.........
示例14: QTableView
/* we create a table that has a fixed height, but can stretch to fit certain width */
QTableView *PrintLayout::createProfileTable(ProfilePrintModel *model, const int tableW)
{
// setup a new table
QTableView *table = new QTableView();
QHeaderView *vHeader = table->verticalHeader();
QHeaderView *hHeader = table->horizontalHeader();
table->setAttribute(Qt::WA_DontShowOnScreen);
table->setSelectionMode(QAbstractItemView::NoSelection);
table->setFocusPolicy(Qt::NoFocus);
table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
hHeader->setVisible(false);
vHeader->setVisible(false);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
hHeader->setResizeMode(QHeaderView::Fixed);
vHeader->setResizeMode(QHeaderView::Fixed);
#else
hHeader->setSectionResizeMode(QHeaderView::Fixed);
vHeader->setSectionResizeMode(QHeaderView::Fixed);
#endif
// set the model
table->setModel(model);
/* setup cell span for the table using QTableView::setSpan().
* changes made here reflect on ProfilePrintModel::data(). */
const int cols = model->columnCount();
const int rows = model->rowCount();
// info on top
table->setSpan(0, 0, 1, 4);
table->setSpan(1, 0, 1, 4);
// gas used
table->setSpan(2, 0, 1, 2);
table->setSpan(3, 0, 1, 2);
// notes
table->setSpan(6, 0, 1, 5);
table->setSpan(7, 0, 5, 5);
/* resize row heights to the 'profilePrintRowHeights' indexes.
* profilePrintTableMaxH will then hold the table height. */
int i;
profilePrintTableMaxH = 0;
for (i = 0; i < rows; i++) {
int h = profilePrintRowHeights.at(i);
profilePrintTableMaxH += h;
vHeader->resizeSection(i, h);
}
// resize columns. columns widths are percentages from the table width.
int accW = 0;
for (i = 0; i < cols; i++) {
int pw = qCeil((qreal)(profilePrintColumnWidths.at(i) * tableW) / 100.0);
accW += pw;
if (i == cols - 1 && accW > tableW) /* adjust last column */
pw -= accW - tableW;
hHeader->resizeSection(i, pw);
}
// resize
table->resize(tableW, profilePrintTableMaxH);
// hide the grid and set a stylesheet
table->setItemDelegate(new ProfilePrintDelegate(this));
table->setShowGrid(false);
table->setStyleSheet(
"QTableView { border: none }"
"QTableView::item { border: 0px; padding-left: 2px; padding-right: 2px; }");
// return
return table;
}