当前位置: 首页>>代码示例>>C++>>正文


C++ QTableView::setItemDelegateForRow方法代码示例

本文整理汇总了C++中QTableView::setItemDelegateForRow方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setItemDelegateForRow方法的具体用法?C++ QTableView::setItemDelegateForRow怎么用?C++ QTableView::setItemDelegateForRow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTableView的用法示例。


在下文中一共展示了QTableView::setItemDelegateForRow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ComboBoxDelegate

QTableView * MainWindow::createPropertyView()
{
	QTableView *propertyView = new QTableView;
	propertyView->setFixedWidth(250);


	propertyView->setItemDelegateForRow(1, new ComboBoxDelegate(ComboBoxDelegate::ComboType::Precondition));

	/*
	const int nHeaderCount = 2;

	QStandardItemModel *model = new QStandardItemModel;
	model->setColumnCount(nHeaderCount);
	model->setHeaderData(0, Qt::Horizontal, tr("Property"));
	model->setHeaderData(1, Qt::Horizontal, tr("Value"));

	propertyView->setModel(model);
	propertyView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);

	propertyView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
	propertyView->setColumnWidth(0, 101);

	for (int i=0; i<nHeaderCount; ++i)
	{
		model->setItem(i, 0, new QStandardItem("2009441676"));
		model->item(i, 0)->setForeground(QBrush(QColor(255, 0, 0)));
		model->item(i, 0)->setTextAlignment(Qt::AlignCenter);
		model->setItem(i, 1, new QStandardItem(QString::fromLocal8Bit("¹þ¹þ")));
	}
	*/

	return propertyView;
}
开发者ID:RayRiver,项目名称:QBTEditor,代码行数:33,代码来源:mainwindow.cpp

示例2: 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, const qreal fitNotesToHeight)
{
	// 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, 3);
	table->setSpan(1, 0, 1, 3);
	table->setSpan(0, 3, 1, 2);
	table->setSpan(1, 3, 1, 2);
	// 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.
	 * what fitNotesToHeight does it to expand the notes section to fit a special height */
	int i;
	profilePrintTableMaxH = 0;
	for (i = 0; i < rows; i++) {
		int h = (i == rows - 1 && fitNotesToHeight != 0.0) ? fitNotesToHeight : 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(table));
	table->setItemDelegateForRow(7, new HTMLDelegate(table));

	table->setShowGrid(false);
	table->setStyleSheet(
		"QTableView { border: none }"
		"QTableView::item { border: 0px; padding-left: 2px; padding-right: 2px; }");
	// return
	return table;
}
开发者ID:Cgruppo,项目名称:subsurface,代码行数:72,代码来源:printlayout.cpp


注:本文中的QTableView::setItemDelegateForRow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。