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


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

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


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

示例1: 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;
    }
开发者ID:kspagnoli,项目名称:fbb,代码行数:53,代码来源:old_main.cpp

示例2: 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);
}
开发者ID:crobertd,项目名称:qtbase,代码行数:27,代码来源:tst_qitemdelegate.cpp

示例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")));
}
开发者ID:victorkifer,项目名称:VKAudioPlayer,代码行数:31,代码来源:mainwindow.cpp

示例4: main

int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(interview);

    QApplication app(argc, argv);
    QSplitter page;

    QAbstractItemModel *data = new Model(1000, 10, &page);
    QItemSelectionModel *selections = new QItemSelectionModel(data);

    QTableView *table = new QTableView;
    table->setModel(data);
    table->setSelectionModel(selections);
    table->horizontalHeader()->setMovable(true);
    table->verticalHeader()->setMovable(true);
    // Set StaticContents to enable minimal repaints on resizes.
    table->viewport()->setAttribute(Qt::WA_StaticContents);
    page.addWidget(table);

    QTreeView *tree = new QTreeView;
    tree->setModel(data);
    tree->setSelectionModel(selections);
    tree->setUniformRowHeights(true);
    tree->header()->setStretchLastSection(false);
    tree->viewport()->setAttribute(Qt::WA_StaticContents);
    // Disable the focus rect to get minimal repaints when scrolling on Mac.
    tree->setAttribute(Qt::WA_MacShowFocusRect, false);
    page.addWidget(tree);

    QListView *list = new QListView;
    list->setModel(data);
    list->setSelectionModel(selections);
    list->setViewMode(QListView::IconMode);
    list->setSelectionMode(QAbstractItemView::ExtendedSelection);
    list->setAlternatingRowColors(false);
    list->viewport()->setAttribute(Qt::WA_StaticContents);
    list->setAttribute(Qt::WA_MacShowFocusRect, false);
    page.addWidget(list);

    page.setWindowIcon(QPixmap(":/images/interview.png"));
    page.setWindowTitle("Interview");
    page.show();

    return app.exec();
}
开发者ID:maxxant,项目名称:qt,代码行数:45,代码来源:main.cpp

示例5: QWidget

TransactionView::TransactionView(QWidget *parent) :
    QWidget(parent), model(0), transactionProxyModel(0),
    transactionView(0)
{
    setContentsMargins(0,0,0,0);
    QHBoxLayout *hlayout = new QHBoxLayout();
    hlayout->setContentsMargins(0,0,0,0);

#ifdef Q_OS_MAC
    hlayout->setSpacing(5);
    hlayout->addSpacing(26);
#else
    hlayout->setSpacing(0);
    hlayout->addSpacing(23);
#endif

    // Build filter row
    dateWidget = new QComboBox(this);
#ifdef Q_OS_MAC
    dateWidget->setFixedWidth(151);
#else
    dateWidget->setFixedWidth(150);
#endif
    dateWidget->addItem(tr("All"), All);
    dateWidget->addItem(tr("Today"), Today);
    dateWidget->addItem(tr("This week"), ThisWeek);
    dateWidget->addItem(tr("This month"), ThisMonth);
    dateWidget->addItem(tr("Last month"), LastMonth);
    dateWidget->addItem(tr("This year"), ThisYear);
    dateWidget->addItem(tr("Range..."), Range);
    hlayout->addWidget(dateWidget);

    typeWidget = new QComboBox(this);
#ifdef Q_OS_MAC
    typeWidget->setFixedWidth(121);
#else
    typeWidget->setFixedWidth(120);
#endif

    typeWidget->addItem(tr("All"), TransactionFilterProxy::ALL_TYPES);
    typeWidget->addItem(tr("Received with"), TransactionFilterProxy::TYPE(TransactionRecord::RecvWithAddress) |
                                        TransactionFilterProxy::TYPE(TransactionRecord::RecvFromOther));
    typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) |
                                  TransactionFilterProxy::TYPE(TransactionRecord::SendToOther));
    typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
    typeWidget->addItem(tr("Interest"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
    typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));

    hlayout->addWidget(typeWidget);

    addressWidget = new QLineEdit(this);
#if QT_VERSION >= 0x040700
    /* Do not move this to the XML file, Qt before 4.7 will choke on it */
    addressWidget->setPlaceholderText(tr("Enter address or label to search"));
#endif
    hlayout->addWidget(addressWidget);

    amountWidget = new QLineEdit(this);
#if QT_VERSION >= 0x040700
    /* Do not move this to the XML file, Qt before 4.7 will choke on it */
    amountWidget->setPlaceholderText(tr("Min amount"));
#endif
    amountWidget->setFixedWidth(100);
    amountWidget->setValidator(new QDoubleValidator(0, 1e20, 8, this));
    hlayout->addWidget(amountWidget);

    QVBoxLayout *vlayout = new QVBoxLayout(this);
    vlayout->setContentsMargins(0,0,0,0);
    vlayout->setSpacing(0);

    QTableView *view = new QTableView(this);
    view->setFont(qFont);
    view->setMouseTracking(true);
    view->viewport()->setAttribute(Qt::WA_Hover, true);
    view->horizontalHeader()->setHighlightSections(false);
    vlayout->addLayout(hlayout);
    vlayout->addWidget(createDateRangeWidget());
    vlayout->addWidget(view);
    vlayout->setSpacing(0);
    int width = view->verticalScrollBar()->sizeHint().width();
    // Cover scroll bar width with spacing
#ifdef Q_OS_MAC
    hlayout->addSpacing(width+2);
#else
    hlayout->addSpacing(width);
#endif
    // Always show scroll bar
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    view->setTabKeyNavigation(false);
    view->setContextMenuPolicy(Qt::CustomContextMenu);

    transactionView = view;

    totalWidget = new QLabel(this);
    totalWidget->setFont(qFont);
    totalWidget->setAlignment(Qt::AlignBottom | Qt::AlignRight);
    totalWidget->setLayoutDirection(Qt::RightToLeft);
    totalWidget->setFixedHeight(27);
    totalWidget->setFixedWidth(300);
    totalWidget->setText(tr("Total: "));
//.........这里部分代码省略.........
开发者ID:benzhi888,项目名称:renminbi,代码行数:101,代码来源:transactionview.cpp

示例6: placeButton

void Button::placeButton()
{
    QTableView* table = qobject_cast<QTableView*>(this->parent());
    if (!table)
    {
        setVisible(false);
        return ;
    }

    if (_point.isNull())
    {
        QSize s = table->viewport()->size();
        //qDebug() << s;
        _point = QPoint(s.width(),s.height());
    }

    QAbstractItemModel* model = table->model();
    if (!model)
        return;

    int n,m,bsize1,bsize2,offset1,offset2,point1,point2;
    getSizes(table,model,&m,&n,&bsize1,&bsize2,&point1,&point2,&offset1,&offset2);

    int coord1;
    int coord2 = 0;

    int sizes[m];
    if (_orientation == Qt::Horizontal)
    {
        for (int i=0;i<m;i++)
            sizes[i] = table->columnWidth(i);
        for (int i=0;i<n;i++)
            coord2 += table->rowHeight(i);
    }
    else
    {
        for (int i=0;i<m;i++)
            sizes[i] = table->rowHeight(i);
        for (int i=0;i<n;i++)
            coord2 += table->columnWidth(i);
    }

    if (_type == InsertRemove::Insert)
        nearestBorder(_policy,point1+offset1,sizes,m,&_modelIndex,&coord1);
    else // _type == InsertRemove::Remove
        nearestMiddle(_policy,point1+offset1,sizes,m,&_modelIndex,&coord1);


    coord1 -= bsize1 / 2;

    QSize vp = usefulWidgetSize(table);
    QPoint sh = table->viewport()->mapToParent(QPoint(0,0)); //насколько viewport меньше table

    if (_orientation == Qt::Horizontal)
    {
        if (coord2 - offset2 + bsize2 + sh.y() > vp.height())
            coord2 = vp.height() - bsize2 + offset2 - sh.y();
    }
    else
    {
        if (coord2 - offset2 + bsize2 + sh.x() > vp.width())
            coord2 = vp.width() - bsize2 + offset2 - sh.x();
    }

    if (_orientation == Qt::Horizontal)
    {
        QPoint p = table->viewport()->mapToParent(QPoint(coord1 - offset1,coord2 - offset2));
        setGeometry(QRect(p,size()));
    }
    else
    {
        QPoint p = table->viewport()->mapToParent(QPoint(coord2 - offset2,coord1 - offset1));
        setGeometry(QRect(p,size()));
    }

    if (_type == InsertRemove::Insert)
    {
        setVisible(_modelIndex>=0);
    }
    else
    {
        setVisible((_policy & InsertRemove::RemoveAllowed) && (_modelIndex>-1));
    }

}
开发者ID:overloop,项目名称:insertremovepanel,代码行数:85,代码来源:insertremove_button.cpp

示例7: main

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    ToDoListModel model;

    // Labels with totals

    QLabel * lcEffort = new QLabel;
    TotalEstimateLabel * lEffort = new TotalEstimateLabel;
    lcEffort->setText("Total Effort");
    QObject::connect(&model, SIGNAL(totalEffortChanged(int)),
                     lEffort, SLOT(setTotalEstimate(int)));


    QLabel * lcEstimated = new QLabel();
    TotalEstimateLabel * lEstimated = new TotalEstimateLabel();
    lcEstimated->setText("Estimated Effort");
    QObject::connect(&model, SIGNAL(totalEstimateChanged(int)),
                     lEstimated, SLOT(setTotalEstimate(int)));


    QFormLayout * form1 = new QFormLayout;
    form1->addRow(lcEffort, lEffort);
    form1->addRow(lcEstimated, lEstimated);

    // Table with tasks

    QTableView *table = new QTableView;

    // TODO enable drag and drop for moving cells
    table->setDragEnabled(true);
    table->viewport()->setAcceptDrops(true);
    table->setDropIndicatorShown(true);
    table->setDragDropMode(QAbstractItemView::InternalMove);

    // Init model after the signal is set.

    QList<ToDoItem> tasks;
    for (int row = 0; row < 100; ++row) {
       ToDoItem ti;
       ti.name = QString("Task %0").arg(row + 1);
       ti.estimated_minutes = row + 1;
       ti.was_done = false;
       tasks.append(ti);
    }
    model.appendTasks(tasks);

    // NOTE: add now the model, otherwise the table does not show data.
    table->setModel(&model);

    // Add widgets to the main layout
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addLayout(form1);
    layout->addWidget(table);

    // Create main window
    QWidget window;
    window.setLayout(layout);
    window.setWindowTitle("Lazy GUI Chooser - QT");
    window.show();

    return app.exec();
}
开发者ID:Haskell-ITA,项目名称:lazy-gui-choice,代码行数:63,代码来源:app.cpp


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