本文整理汇总了C++中QTableView::horizontalHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableView::horizontalHeader方法的具体用法?C++ QTableView::horizontalHeader怎么用?C++ QTableView::horizontalHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableView
的用法示例。
在下文中一共展示了QTableView::horizontalHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
tableView->setGridStyle(Qt::NoPen);
QHeaderView * verticalHeader = tableView->verticalHeader();
verticalHeader->setDefaultSectionSize(57);
tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
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);
}
示例2: initializeTable
void availableRoomsWindow::initializeTable()
{
qDebug() << Q_FUNC_INFO;
QTableView* tableView = ui->tableView;
tableView->setModel(parameters->availableRoomsMdl);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setAlternatingRowColors(true);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->horizontalHeader()->setHighlightSections(false);
tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
tableView->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
tableView->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents);
tableView->hideColumn(1);
tableView->hideColumn(6);
tableView->hideColumn(7);
tableView->hideColumn(8);
tableView->hideColumn(9);
tableView->hideColumn(10);
tableView->hideColumn(11);
tableView->hideColumn(12);
tableView->hideColumn(13);
tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
ui->tableView->verticalHeader()->setDefaultSectionSize(23);
}
示例3: 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")));
}
示例4: 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();
}
示例5: 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);
}
示例6: editKernel
void ConvolveMatrixEffectConfigWidget::editKernel()
{
if (!m_effect) {
return;
}
QVector<qreal> oldKernel = m_effect->kernel();
QPoint kernelSize = m_effect->order();
m_matrixModel->setMatrix(oldKernel, kernelSize.y(), kernelSize.x());
connect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(kernelChanged()));
QPointer<QDialog> dlg = new QDialog(this);
QTableView *table = new QTableView(dlg);
table->setModel(m_matrixModel);
table->horizontalHeader()->hide();
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
table->verticalHeader()->hide();
table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
QVBoxLayout *mainLayout = new QVBoxLayout;
dlg->setLayout(mainLayout);
mainLayout->addWidget(table);
if (dlg->exec() == QDialog::Accepted) {
m_effect->setKernel(m_matrixModel->matrix());
emit filterChanged();
} else {
m_effect->setKernel(oldKernel);
}
delete dlg;
disconnect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(kernelChanged()));
}
示例7: KFilterEffectConfigWidgetBase
ColorMatrixEffectConfigWidget::ColorMatrixEffectConfigWidget(QWidget *parent)
: KFilterEffectConfigWidgetBase(parent), m_effect(0)
{
QGridLayout * g = new QGridLayout(this);
m_type = new KComboBox(this);
m_type->addItem(i18n("Apply color matrix"));
m_type->addItem(i18n("Saturate colors"));
m_type->addItem(i18n("Rotate hue"));
m_type->addItem(i18n("Luminance to alpha"));
g->addWidget(m_type, 0, 0);
m_stack = new QStackedWidget(this);
m_stack->setContentsMargins(0, 0, 0, 0);
g->addWidget(m_stack, 1, 0);
m_matrixModel = new MatrixDataModel(this);
QTableView * matrixWidget = new QTableView(m_stack);
matrixWidget->setModel(m_matrixModel);
matrixWidget->horizontalHeader()->hide();
matrixWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
matrixWidget->verticalHeader()->hide();
matrixWidget->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
m_stack->addWidget(matrixWidget);
QWidget * saturateWidget = new QWidget(m_stack);
QGridLayout * saturateLayout = new QGridLayout(saturateWidget);
saturateLayout->addWidget(new QLabel(i18n("Saturate value"), saturateWidget), 0, 0);
m_saturate = new KDoubleNumInput(saturateWidget);
m_saturate->setRange(0.0, 1.0, 0.05, false);
saturateLayout->addWidget(m_saturate, 0, 1);
saturateLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0);
saturateWidget->setLayout(saturateLayout);
m_stack->addWidget(saturateWidget);
QWidget * hueRotateWidget = new QWidget(m_stack);
QGridLayout * hueRotateLayout = new QGridLayout(hueRotateWidget);
hueRotateLayout->addWidget(new QLabel(i18n("Angle"), hueRotateWidget), 0, 0);
m_hueRotate = new KDoubleNumInput(hueRotateWidget);
m_hueRotate->setRange(0.0, 360.0, 1.0, false);
hueRotateLayout->addWidget(m_hueRotate, 0, 1);
hueRotateLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0);
hueRotateWidget->setLayout(hueRotateLayout);
m_stack->addWidget(hueRotateWidget);
QWidget * luminanceWidget = new QWidget(m_stack);
m_stack->addWidget(luminanceWidget);
setLayout(g);
connect(m_type, SIGNAL(currentIndexChanged(int)), m_stack, SLOT(setCurrentIndex(int)));
connect(m_type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int)));
connect(m_saturate, SIGNAL(valueChanged(double)), this, SLOT(saturateChanged(double)));
connect(m_hueRotate, SIGNAL(valueChanged(double)), this, SLOT(hueRotateChanged(double)));
connect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(matrixChanged()));
}
示例8: addEntry
void AddressOverviewWindow::addEntry(QString firstName,QString lastName,QString address,QString city,QString zipCode)
{
QList< AddressItem > list = model->getList();
AddressItem* addressItem= new AddressItem(firstName,lastName,address,city,zipCode);
if (!list.contains(*addressItem)) {
model->insertRows(0, 1, QModelIndex());
QModelIndex index = model->index(0, 0, QModelIndex());
model->setData(index, firstName, Qt::EditRole);
index = model->index(0, 1, QModelIndex());
model->setData(index, lastName, Qt::EditRole);
index = model->index(0, 2, QModelIndex());
model->setData(index, address, Qt::EditRole);
index = model->index(0, 3, QModelIndex());
model->setData(index, city, Qt::EditRole);
index = model->index(0, 4, QModelIndex());
model->setData(index, zipCode, Qt::EditRole);
QTableView *temp = static_cast<QTableView*>(ui->AddressesTableView);
proxyModel->sort(temp->horizontalHeader()->sortIndicatorSection());
} else {
QMessageBox::information(this, tr("Duplicate Name"),
tr("The adress already exists."));
}
}
示例9: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
TableModel *model = new TableModel(4, 2, &app);
//! [0]
QTableView *firstTableView = new QTableView;
QTableView *secondTableView = new QTableView;
//! [0]
//! [1]
firstTableView->setModel(model);
secondTableView->setModel(model);
//! [1]
firstTableView->horizontalHeader()->setModel(model);
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(QString("(%1, %2)").arg(row).arg(column)));
}
}
//! [2]
secondTableView->setSelectionModel(firstTableView->selectionModel());
//! [2]
firstTableView->setWindowTitle("First table view");
secondTableView->setWindowTitle("Second table view");
firstTableView->show();
secondTableView->show();
return app.exec();
}
示例10: setupTabs
void AddressWidget::setupTabs()
{
QStringList groups;
groups << "ABC" << "DEF" << "GHI" << "JKL" << "MNO" << "PQR" << "STU" << "VW" << "XYZ";
for (int i = 0; i < groups.size(); ++i) {
QString str = groups.at(i);
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(table);
proxyModel->setDynamicSortFilter(true);
QTableView *tableView = new QTableView;
tableView->setModel(proxyModel);
tableView->setSortingEnabled(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->horizontalHeader()->setStretchLastSection(true);
tableView->verticalHeader()->hide();
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
QString newStr = QString("^[%1].*").arg(str);
proxyModel->setFilterRegExp(QRegExp(newStr, Qt::CaseInsensitive));
proxyModel->setFilterKeyColumn(0);
proxyModel->sort(0, Qt::AscendingOrder);
connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SIGNAL(selectionChanged(QItemSelection)));
addTab(tableView, str);
}
}
示例11: goPrint
void DlgCustomizeSpaceball::goPrint()
{
QTableView *view = new QTableView(this);
PrintModel *model = new PrintModel(this, buttonModel, commandModel);
view->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
view->setModel(model);
view->horizontalHeader()->resizeSection(0, 150);
view->horizontalHeader()->resizeSection(1, 300);
view->resize(600, 600);
QPrinter printer;
QPrintDialog printDialog(&printer, this);
if (printDialog.exec() == QDialog::Accepted)
{
QPainter p(&printer);
view->render(&p);
}
}
示例12: 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;
}
示例13: 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();
}
示例14: 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()));
}
示例15: setRightView
void MainWindow::setRightView()
{
QTableView *view = ui->m_rightTableInfo;
view->setModel(m_dirsContentsModel);
view->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
view->horizontalHeader()->resizeSection(0, 280); // 'Name' section. User can resize
view->horizontalHeader()->resizeSection(3, 130); // 'Type' section
connect(view, SIGNAL(activated(QModelIndex)),
view, SLOT(clearSelection())); // NOTE: must be the first connection
connect(view, SIGNAL(activated(QModelIndex)),
this, SLOT(slotSetLeftViewCurrentIndex(QModelIndex)));
connect(view, SIGNAL(activated(QModelIndex)),
this, SLOT(slotActivatedOnlyDirs(QModelIndex)));
connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(slotUpdateSelection(QItemSelection,QItemSelection)));
}