本文整理汇总了C++中QTableView::setItemDelegate方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setItemDelegate方法的具体用法?C++ QTableView::setItemDelegate怎么用?C++ QTableView::setItemDelegate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::setItemDelegate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStandardItemModel model(4, 2);
QTableView tableView;
tableView.setModel(&model);
SpinBoxDelegate delegate;
tableView.setItemDelegate(&delegate);
//! [0]
tableView.horizontalHeader()->setStretchLastSection(true);
//! [1]
for (int row = 0; row < 4; ++row) {
for (int column = 0; column < 2; ++column) {
QModelIndex index = model.index(row, column, QModelIndex());
model.setData(index, QVariant((row+1) * (column+1)));
}
//! [1] //! [2]
}
//! [2]
//! [3]
tableView.setWindowTitle(QObject::tr("Spin Box Delegate"));
tableView.show();
return app.exec();
}
示例2: createTable
/*!
Create and return the table used to visualize digital signals.
*/
QTableView* UiDigitalGenerator::createTable()
{
// Deallocation: "Qt Object trees" (See UiMainWindow)
QTableView* table = new QTableView(this);
QItemSelectionModel* m = table->selectionModel();
if (m != NULL) delete m;
table->setModel(mSignals);
// Deallocation: "Qt Object trees" (See UiMainWindow)
DigitalDelegate* delegate = new DigitalDelegate(this);
QAbstractItemDelegate* d = table->itemDelegate();
if (d != NULL) delete d;
table->setItemDelegate(delegate);
table->resizeColumnsToContents();
table->resizeRowsToContents();
connect(table->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this,
SLOT(handleSelectionChanged(QItemSelection,QItemSelection)));
return table;
}
示例3: createRelationTableView
QTableView* EkonTables::createRelationTableView(QWidget *parentWidget, QSqlRelationalTableModel *model)
{
QTableView *tableView = createTableView(parentWidget, model);
tableView->setItemDelegate(new QSqlRelationalDelegate(tableView));
return tableView;
}
示例4: QWidget
ErrorListView::ErrorListView(QWidget* parent)
: QWidget(parent),
m_model(0)
{
m_model = new ErrorListModel(this);
QTableView* tableView = new QTableView;
tableView->setItemDelegate(new ItemDelegate);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setAlternatingRowColors(true);
tableView->setShowGrid(false);
tableView->verticalHeader()->hide();
tableView->setModel(m_model);
#ifdef STROMX_STUDIO_QT4
tableView->horizontalHeader()->setResizeMode(ErrorListModel::TIME, QHeaderView::Interactive);
tableView->horizontalHeader()->setResizeMode(ErrorListModel::DESCRIPTION, QHeaderView::Stretch);
#else
tableView->horizontalHeader()->setSectionResizeMode(ErrorListModel::TIME, QHeaderView::Interactive);
tableView->horizontalHeader()->setSectionResizeMode(ErrorListModel::DESCRIPTION, QHeaderView::Stretch);
#endif // STROMX_STUDIO_QT4
QPushButton* clearButton = new QPushButton(tr("Clear error log"));
connect(clearButton, SIGNAL(clicked()), m_model, SLOT(clear()));
QHBoxLayout* buttonLayout = new QHBoxLayout;
buttonLayout->addWidget(clearButton);
buttonLayout->addStretch();
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget(tableView);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
}
示例5: model
void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck()
{
QStandardItemModel model(3, 1);
for (int i = 0; i < 3; ++i) {
QStandardItem *item = new QStandardItem(QLatin1String("Item ") + QString::number(i));
item->setCheckable(true);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
model.setItem(i, item);
}
QTableView view;
view.setModel(&model);
view.setItemDelegate(new TestItemDelegate);
view.show();
view.selectAll();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QStyleOptionViewItem option;
option.rect = view.visualRect(model.index(0, 0));
// mimic QStyledItemDelegate::initStyleOption logic
option.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator;
option.checkState = Qt::CheckState(model.index(0, 0).data(Qt::CheckStateRole).toInt());
const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1;
QPoint pos = qApp->style()->subElementRect(QStyle::SE_ViewItemCheckIndicator, &option, 0).center()
+ QPoint(checkMargin, 0);
QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos);
QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex()));
QCOMPARE(model.item(0)->checkState(), Qt::Checked);
}
示例6: QSqlRelationalDelegate
QTableView *createView(const QString &title, QSqlTableModel *model)
{
QTableView *view = new QTableView;
view->setModel(model);
view->setItemDelegate(new QSqlRelationalDelegate(view));
view->setWindowTitle(title);
return view;
}
示例7: main
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QTableView* table = new QTableView();
TableModel* model = new TableModel(table);
MultipleSelectDelegate* delegate = new MultipleSelectDelegate(table);
table->setModel(model);
table->setItemDelegate(delegate);
table->show();
return app.exec();
}
示例8: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTableView tv;
QStandardItemModel m;
m.setRowCount(4);
m.setColumnCount(2);
tv.setModel(&m);
tv.show();
tv.setItemDelegate(new ExampleDelegate());
app.exec();
}
示例9: QDialog
Departments::Departments(QSqlDatabase& db, QWidget *parent): QDialog(parent),
ui(new Ui::Departments), _db(&db) {
ui->setupUi(this);
_searchAgain = true;
_model = new QSqlRelationalTableModel(this, *_db);
_model->setTable("departments");
_model->setEditStrategy(QSqlTableModel::OnFieldChange);
_model->setRelation(2, QSqlRelation("faculties", "fc_id", "fc_name"));
reloadTable();
QTableView* view = ui->tableView;
view->setModel(_model);
view->setItemDelegate(new QSqlRelationalDelegate(view));
}
示例10: 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();
}
}
示例11: QComboBox
MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags f) :
QMainWindow(parent, f),
configurationModels(),
geometryModels(),
ikAlgorithmComboBox(new QComboBox(this)),
ikDurationSpinBox(new QSpinBox(this)),
ikIterationsSpinBox(new QSpinBox(this)),
ikJacobianComboBox(new QComboBox(this)),
kinematicModels(),
operationalModels(),
scene(),
configurationDelegates(),
configurationDockWidget(new QDockWidget(this)),
configurationTabWidget(new QTabWidget(this)),
configurationViews(),
gradientBackground(),
operationalDelegates(),
operationalDockWidget(new QDockWidget(this)),
operationalTabWidget(new QTabWidget(this)),
operationalViews(),
saveImageWithAlphaAction(new QAction(this)),
saveImageWithoutAlphaAction(new QAction(this)),
saveSceneAction(new QAction(this)),
server(new Server(this)),
viewer(nullptr)
{
MainWindow::singleton = this;
SoQt::init(this);
SoDB::init();
SoGradientBackground::initClass();
std::shared_ptr<rl::sg::Factory> geometryFactory;
std::string geometryFilename = QApplication::arguments()[1].toStdString();
if ("urdf" == geometryFilename.substr(geometryFilename.length() - 4, 4))
{
geometryFactory = std::make_shared<rl::sg::UrdfFactory>();
}
else
{
geometryFactory = std::make_shared<rl::sg::XmlFactory>();
}
this->scene = std::make_shared<rl::sg::so::Scene>();
geometryFactory->load(geometryFilename, this->scene.get());
for (int i = 2; i < QApplication::arguments().size(); ++i)
{
std::shared_ptr<rl::mdl::Factory> kinematicFactory;
std::string kinematicFilename = QApplication::arguments()[i].toStdString();
if ("urdf" == kinematicFilename.substr(kinematicFilename.length() - 4, 4))
{
kinematicFactory = std::make_shared<rl::mdl::UrdfFactory>();
}
else
{
kinematicFactory = std::make_shared<rl::mdl::XmlFactory>();
}
this->geometryModels.push_back(this->scene->getModel(i - 2));
this->kinematicModels.push_back(std::dynamic_pointer_cast<rl::mdl::Kinematic>(kinematicFactory->create(kinematicFilename)));
}
for (std::size_t i = 0; i < this->kinematicModels.size(); ++i)
{
ConfigurationDelegate* configurationDelegate = new ConfigurationDelegate(this);
configurationDelegate->id = i;
this->configurationDelegates.push_back(configurationDelegate);
ConfigurationModel* configurationModel = new ConfigurationModel(this);
configurationModel->id = i;
this->configurationModels.push_back(configurationModel);
QTableView* configurationView = new QTableView(this);
#if QT_VERSION >= 0x050000
configurationView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else // QT_VERSION
configurationView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif // QT_VERSION
configurationView->horizontalHeader()->hide();
configurationView->setAlternatingRowColors(true);
configurationView->setItemDelegate(configurationDelegate);
configurationView->setModel(configurationModel);
this->configurationViews.push_back(configurationView);
this->configurationTabWidget->addTab(configurationView, QString::number(i));
OperationalDelegate* operationalDelegate = new OperationalDelegate(this);
this->operationalDelegates.push_back(operationalDelegate);
OperationalModel* operationalModel = new OperationalModel(this);
operationalModel->id = i;
this->operationalModels.push_back(operationalModel);
QTableView* operationalView = new QTableView(this);
#if QT_VERSION >= 0x050000
operationalView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else // QT_VERSION
//.........这里部分代码省略.........
示例12: 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;
}