本文整理汇总了C++中QTableView::setItemDelegateForColumn方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::setItemDelegateForColumn方法的具体用法?C++ QTableView::setItemDelegateForColumn怎么用?C++ QTableView::setItemDelegateForColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::setItemDelegateForColumn方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QDialog
CPropertiesDialog::CPropertiesDialog( QWidget *pwidgetParent, HODBCINSTPROPERTY hFirstProperty )
: QDialog( pwidgetParent )
{
QVBoxLayout * playout = new QVBoxLayout;
QTableView * ptableview = new QTableView;
QFrame * pframe = new QFrame;
QDialogButtonBox * pdialogbuttonbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok | QDialogButtonBox::Help );
pframe->setFrameStyle( QFrame::HLine );
ppropertiesmodel = new CPropertiesModel( 0, hFirstProperty );
ppropertiesdelegate = new CPropertiesDelegate;
ptableview->setModel( ppropertiesmodel );
ptableview->setItemDelegateForColumn ( 1, ppropertiesdelegate );
ptableview->verticalHeader()->hide();
connect( pdialogbuttonbox, SIGNAL(accepted()), this, SLOT(accept()) );
connect( pdialogbuttonbox, SIGNAL(rejected()), this, SLOT(reject()) );
playout->addWidget( ptableview, 10 );
playout->addWidget( pframe );
playout->addWidget( pdialogbuttonbox );
setWindowIcon( QPixmap( xpmODBC ) );
setLayout( playout );
doLoadState();
}
示例2: main
int main(int argc, char *argv[])
{
std::cout << "Enter." << std::endl;
QApplication app(argc, argv);
QStandardItemModel model(4, 2);
QTableView tableView;
tableView.setModel(&model);
ComboBoxDelegate delegate;
//tableView.setItemDelegate(&delegate);
tableView.setItemDelegateForColumn(1, &delegate); // Column 0 can take any value, column 1 can only take values up to 8.
//tableView.horizontalHeader()->setStretchLastSection(true);
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)));
}
}
tableView.show();
return app.exec();
}
示例3: QWidget
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
ui.setupUi(this);
ui.dateEdit->setDisplayFormat(getDateFormat());
ui.tableWidget->setTitle(tr("Dive planner points"));
ui.tableWidget->setModel(DivePlannerPointsModel::instance());
DivePlannerPointsModel::instance()->setRecalc(true);
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
ui.cylinderTableWidget->setTitle(tr("Available gases"));
ui.cylinderTableWidget->setModel(CylindersModel::instance());
QTableView *view = ui.cylinderTableWidget->view();
view->setColumnHidden(CylindersModel::START, true);
view->setColumnHidden(CylindersModel::END, true);
view->setColumnHidden(CylindersModel::DEPTH, false);
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
GasSelectionModel::instance(), SLOT(repopulate()));
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
plannerModel, SIGNAL(cylinderModelEdited()));
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex, int, int)),
plannerModel, SIGNAL(cylinderModelEdited()));
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
plannerModel, SIGNAL(cylinderModelEdited()));
ui.tableWidget->setBtnToolTip(tr("Add dive data point"));
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
connect(ui.dateEdit, SIGNAL(dateChanged(QDate)), plannerModel, SLOT(setStartDate(QDate)));
connect(ui.ATMPressure, SIGNAL(valueChanged(int)), this, SLOT(atmPressureChanged(int)));
connect(ui.atmHeight, SIGNAL(valueChanged(int)), this, SLOT(heightChanged(int)));
connect(ui.salinity, SIGNAL(valueChanged(double)), this, SLOT(salinityChanged(double)));
connect(DivePlannerPointsModel::instance(), SIGNAL(startTimeChanged(QDateTime)), this, SLOT(setupStartTime(QDateTime)));
// Creating (and canceling) the plan
replanButton = ui.buttonBox->addButton(tr("Save new"), QDialogButtonBox::ActionRole);
connect(replanButton, SIGNAL(clicked()), plannerModel, SLOT(saveDuplicatePlan()));
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(savePlan()));
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
connect(closeKey, SIGNAL(activated()), plannerModel, SLOT(cancelPlan()));
// This makes shure the spinbox gets a setMinimum(0) on it so we can't have negative time or depth.
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DEPTH, new SpinBoxDelegate(0, INT_MAX, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, INT_MAX, 1, this));
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.1, this));
/* set defaults. */
ui.ATMPressure->setValue(1013);
ui.atmHeight->setValue(0);
setMinimumWidth(0);
setMinimumHeight(0);
}
示例4: 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();
}
}
示例5: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//QListView view;
QTableView view;
view.setSortingEnabled(false);
view.horizontalHeader()->setStretchLastSection(true);
view.horizontalHeader()->setVisible(false);
view.verticalHeader()->setVisible(false);
MillionRows model(Q_NULLPTR);
view.setModel(&model);
view.setAlternatingRowColors(true);
view.setStyleSheet("alternate-background-color: green;background-color: white;");
view.setItemDelegateForColumn(0, new TableStyleDelegate());
view.resizeRowsToContents(); // impact performance - force call sizeHint
view.show();
return a.exec();
}
示例6: main
int main(int argc, char ** argv) {
QApplication app{argc, argv};
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
if (! db.open()) return 1;
db.exec("create table example (name text, inuse numeric);");
db.exec("insert into example (name, inuse) values "
"('Zaphod', 0), ('Beeblebrox', 1);");
QSqlTableModel model;
model.setTable("example");
model.select();
BoolProxy proxy{1};
proxy.setSourceModel(&model);
QTableView ui;
YesNoDelegate delegate;
ui.setItemDelegateForColumn(1, &delegate);
ui.setModel(&proxy);
ui.show();
return app.exec();
}
示例7: main
int main( int argc, char **argv )
{
QApplication app( argc, argv );
QTableView table;
QStandardItemModel model( 10, 2 );
for( int r=0; r<10; ++r )
{
QStandardItem *item = new QStandardItem( QString("Row %1").arg(r+1) );
item->setEditable( false );
model.setItem( r, 0, item );
model.setItem( r, 1, new QStandardItem( QString::number((r*30)%100 )) );
}
table.setModel( &model );
BarDelegate delegate;
table.setItemDelegateForColumn( 1, &delegate );
table.show();
return app.exec();
}
示例8: QMainWindow
OLD_MAIN(QWidget* pParent = nullptr)
: QMainWindow(pParent)
{
Q_INIT_RESOURCE(Resources);
// Settings persistence
ReadSettings();
// Appearance LUT
PlayerApperances appearances;
// Build player table model from file
PlayerTableModel* playerTableModel = new PlayerTableModel(this);
playerTableModel->LoadHittingProjections(appearances);
playerTableModel->LoadPitchingProjections(appearances);
playerTableModel->CalculateHittingScores();
playerTableModel->CalculatePitchingScores();
playerTableModel->InitializeTargetValues();
// Draft delegate
DraftDelegate* draftDelegate = new DraftDelegate(playerTableModel);
LinkDelegate* linkDelegate = new LinkDelegate(this);
TagDelegate* tagDelegate = new TagDelegate(this);
// Hitter sort-model
PlayerSortFilterProxyModel* hitterSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Hitter);
hitterSortFilterProxyModel->setSourceModel(playerTableModel);
hitterSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole);
// Hitter table view
QTableView* hitterTableView = MakeTableView(hitterSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z);
hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate);
hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate);
hitterTableView->setItemDelegateForColumn(FindColumn(hitterSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate);
hitterTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
// Context menu
QMenu* contextMenu = new QMenu();
contextMenu->addAction("&Remove Player");
// Apply to hitter table view
hitterTableView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(hitterTableView, &QWidget::customContextMenuRequested, [=](const QPoint& pos) {
QPoint globalPos = hitterTableView->mapToGlobal(pos);
QAction* selectedItem = contextMenu->exec(globalPos);
if (selectedItem) {
auto proxyIndex = hitterTableView->indexAt(pos);
auto srcIndex = hitterSortFilterProxyModel->mapToSource(proxyIndex);
playerTableModel->RemovePlayer(srcIndex.row());
}
});
// Pitcher sort-model
PlayerSortFilterProxyModel* pitcherSortFilterProxyModel = new PlayerSortFilterProxyModel(Player::Pitcher);
pitcherSortFilterProxyModel->setSourceModel(playerTableModel);
pitcherSortFilterProxyModel->setSortRole(PlayerTableModel::RawDataRole);
// Pitcher table view
QTableView* pitcherTableView = MakeTableView(pitcherSortFilterProxyModel, true, PlayerTableModel::COLUMN_Z);
pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_DRAFT_BUTTON), draftDelegate);
pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_ID_LINK), linkDelegate);
pitcherTableView->setItemDelegateForColumn(FindColumn(pitcherSortFilterProxyModel, PlayerTableModel::COLUMN_FLAG), tagDelegate);
pitcherTableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
// Top/Bottom splitter
QSplitter* topBottomSplitter = new QSplitter(Qt::Vertical);
topBottomSplitter->setContentsMargins(5, 5, 5, 5);
// Hitter/Pitcher tab View
enum PlayerTableTabs { Hitters, Pitchers, Unknown };
QTabWidget* hitterPitcherTabs = new QTabWidget(this);
hitterPitcherTabs->insertTab(PlayerTableTabs::Hitters, hitterTableView, "Hitters");
hitterPitcherTabs->insertTab(PlayerTableTabs::Pitchers, pitcherTableView, "Pitchers");
topBottomSplitter->addWidget(hitterPitcherTabs);
// Tab lookup helper
auto CaterogyToTab = [](uint32_t catergory)
{
switch (catergory)
{
case Player::Hitter:
return PlayerTableTabs::Hitters;
case Player::Pitcher:
return PlayerTableTabs::Pitchers;
default:
return PlayerTableTabs::Unknown;
}
};
// Drafted filter action
QAction* filterDrafted = new QAction(this);
connect(filterDrafted, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted);
connect(filterDrafted, &QAction::toggled, pitcherSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterDrafted);
filterDrafted->setText(tr("Drafted"));
filterDrafted->setToolTip("Toggle Drafted Players");
filterDrafted->setCheckable(true);
filterDrafted->toggle();
QAction* filterReplacement = new QAction(this);
connect(filterReplacement, &QAction::toggled, hitterSortFilterProxyModel, &PlayerSortFilterProxyModel::OnFilterReplacement);
//.........这里部分代码省略.........
示例9: addProject
void ContributoriesWidget::addProject(QPair<Project*, Rate>* p)
{
if(p == 0) {
_modelProjects->append();
} else {
_modelProjects->append(*p);
}
QTableView* view = new QTableView();
_modelsContributories << new WdgModels::ContributoriesTableModel();
view->setModel(_modelsContributories.last());
view->setEditTriggers(QAbstractItemView::DoubleClicked);
view->setItemDelegateForColumn(0, new Delegates::TextareaDelegate());
view->setItemDelegateForColumn(1, new Delegates::TextareaDelegate());
view->setItemDelegateForColumn(2, new Delegates::DoubleSpinBoxDelegate());
view->setItemDelegateForColumn(3, new Delegates::UnitComboDelegate());
connect(view->itemDelegateForColumn(3),
SIGNAL(closeEditor(QWidget*)),
SLOT(updatePrice()));
connect(view->itemDelegateForColumn(2),
SIGNAL(closeEditor(QWidget*)),
SLOT(updatePrice()));
connect(view->itemDelegateForColumn(1),
SIGNAL(closeEditor(QWidget*)),
SLOT(updatePrice()));
ui->stack->insertWidget(ui->stack->count(), view);
responsiveContributoriesTable(view);
emit updateUi();
}
示例10: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStandardItemModel model(4,4);
QTableView tableView;
tableView.setModel(&model);
DateDelegate dateDelegate;
tableView.setItemDelegateForColumn(1,&dateDelegate);
ComboDelegate comboDelegate;
tableView.setItemDelegateForColumn(2,&comboDelegate);
SpinDelegate spinDelegate;
tableView.setItemDelegateForColumn(3,&spinDelegate);
model.setHeaderData(0,Qt::Horizontal,QObject::tr("姓名"));
model.setHeaderData(1,Qt::Horizontal,QObject::tr("生日"));
model.setHeaderData(2,Qt::Horizontal,QObject::tr("职业"));
model.setHeaderData(3,Qt::Horizontal,QObject::tr("收入"));
QFile file("test.txt");
if(file.open(QFile::ReadOnly|QFile::Text))
{
QTextStream stream(&file);
QString line;
model.removeRows(0,model.rowCount(QModelIndex()),QModelIndex());
int row =0;
do{
line = stream.readLine();
if(!line.isEmpty())
{
model.insertRows(row,1,QModelIndex());
QStringList pieces = line.split(",",QString::SkipEmptyParts);
model.setData(model.index(row,0,QModelIndex()),pieces.value(0));
model.setData(model.index(row,1,QModelIndex()),pieces.value(1));
model.setData(model.index(row,2,QModelIndex()),pieces.value(2));
model.setData(model.index(row,3,QModelIndex()),pieces.value(3));
row++;
}
}while(!line.isEmpty());
file.close();
}
tableView.setWindowTitle(QObject::tr("Delegate"));
tableView.show();
return a.exec();
}