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


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

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


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

示例1: 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);
    }
}
开发者ID:mimino,项目名称:math_tool,代码行数:34,代码来源:addresswidget.cpp

示例2: loadNetwork

void MainWindow::loadNetwork() 
{
    setWindowTitle("Qt-dtnet - " + ws.networkFilename);

    delete networkToolBox;
    networkToolBox = new QToolBox();
    ui->dockProperties->setWidget(networkToolBox);

    QTableView *propertiesTree;

    std::map<std::string,Population>::iterator i;
    for (i = ws.net->populations.begin(); i != ws.net->populations.end(); ++i)
    {
        propertiesTree = new QTableView();
        propertiesTree->setAlternatingRowColors(false);
        propertiesTree->setSelectionBehavior( QAbstractItemView::SelectRows );
        propertiesTree->setWordWrap( false );
//        propertiesTree->setAnimated( false );
        networkToolBox->addItem(propertiesTree, QString::fromStdString(i->first));
        propertiesModel = new PropModel( &(i->second) );    
        propertiesTree->setModel(propertiesModel);
    }
	
	networkView->replaceNetwork( ws.net );
	networkView->show();
    
    if ( ws.trial->isReady() && ws.net->isReady() ) ui->actionRun_Simulation->setEnabled( true );   
}
开发者ID:baubie,项目名称:dtnet,代码行数:28,代码来源:mainwindow.cpp

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

示例4: 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);

        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);
    }
开发者ID:Airche,项目名称:wificoin,代码行数:28,代码来源:receivecoinsdialog.cpp

示例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);
}
开发者ID:roteroktober,项目名称:stromx-studio,代码行数:35,代码来源:ErrorListView.cpp

示例6: 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

示例7: main

int main( int argc, char **argv )
{
    QApplication app( argc, argv );

    QTreeView *tree = new QTreeView();
    QListView *list = new QListView();
    QTableView *table = new QTableView();

    QSplitter splitter;
    splitter.addWidget(tree);
    splitter.addWidget(list);
    splitter.addWidget(table);

    QStandardItemModel model( 5, 2 );

    for( int r=0; r<5; r++ )
    {
        for( int c=0; c<2; c++)
        {
            QStandardItem *item = new QStandardItem(QString("Row:%0, Column:%1").arg(r).arg(c));

            if(c == 0)
            {
                for(int i=0; i<3; i++)
                {
                    QStandardItem *child = new QStandardItem(QString("Item %0").arg(i));
                    child->setEditable(false);
                    item->appendRow(child);
                }
            }

            model.setItem(r, c, item);
        }
    }

    model.setHorizontalHeaderItem(0, new QStandardItem("Foo"));
    model.setHorizontalHeaderItem(1, new QStandardItem("Bar-Baz"));

    tree->setModel(&model);
    list->setModel(&model);
    table->setModel(&model);

    list->setSelectionModel(tree->selectionModel());
    table->setSelectionModel(tree->selectionModel());

    table->setSelectionBehavior(QAbstractItemView::SelectRows);
    table->setSelectionMode(QAbstractItemView::SingleSelection);

    splitter.show();

    MainWindow w;
    w.show();

    return app.exec();
}
开发者ID:GLDsuh-a,项目名称:qt-1,代码行数:55,代码来源:main.cpp

示例8: 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

示例9: 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();
  }
}
开发者ID:kamawanu,项目名称:wally-imported,代码行数:44,代码来源:settings.cpp

示例10: GalleryView

SongView::SongView(QAbstractGallery *gallery, QWidget *parent, Qt::WindowFlags flags)
    : GalleryView(parent, flags)
    , model(new QGalleryQueryModel(gallery))
{
    model->setRootType(QDocumentGallery::Audio);

    model->addColumn(QDocumentGallery::trackNumber);
    model->setHeaderData(0, Qt::Horizontal, tr("Track"));

    model->addColumn(QDocumentGallery::title);
    model->setHeaderData(1, Qt::Horizontal, tr("Title"));

    model->addColumn(QDocumentGallery::duration);
    model->setHeaderData(2, Qt::Horizontal, tr("Duration"));

    model->addColumn(QDocumentGallery::artist);
    model->setHeaderData(3, Qt::Horizontal, tr("Artist"));

    model->addColumn(QDocumentGallery::albumArtist);
    model->setHeaderData(4, Qt::Horizontal, tr("Album Artist"));

    model->setSortPropertyNames(QStringList()
            << QDocumentGallery::artist
            << QDocumentGallery::albumTitle
            << QDocumentGallery::trackNumber);

    QTableView *view = new QTableView;
    view->setShowGrid(false);
    view->verticalHeader()->setVisible(false);
    view->setSelectionBehavior(QAbstractItemView::SelectRows);
    view->setModel(model.data());
    connect(view, SIGNAL(activated(QModelIndex)), this, SLOT(activated(QModelIndex)));

    QBoxLayout *layout = new QVBoxLayout;
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(view);

    setLayout(layout);
}
开发者ID:KDE,项目名称:android-qt-mobility,代码行数:40,代码来源:songview.cpp

示例11: 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()));
}
开发者ID:Maggunator,项目名称:MITK,代码行数:38,代码来源:QmitkModulesDialog.cpp

示例12: 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);

        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);

        if (model->wallet().getDefaultAddressType() == OutputType::BECH32) {
            ui->useBech32->setCheckState(Qt::Checked);
        } else {
            ui->useBech32->setCheckState(Qt::Unchecked);
        }

        // eventually disable the main receive button if private key operations are disabled
        ui->receiveButton->setEnabled(!model->privateKeysDisabled());
    }
开发者ID:GlobalBoost,项目名称:GlobalBoost-Y,代码行数:37,代码来源:receivecoinsdialog.cpp

示例13: createLayout

void DkFileAssociationsPreference::createLayout() {
	
	QStringList fileFilters = Settings::param().app().openFilters;

	mModel = new QStandardItemModel(this);
	mModel->setObjectName("fileModel");
	for (int rIdx = 1; rIdx < fileFilters.size(); rIdx++)
		mModel->appendRow(getItems(fileFilters.at(rIdx), checkFilter(fileFilters.at(rIdx), Settings::param().app().browseFilters), checkFilter(fileFilters.at(rIdx), Settings::param().app().registerFilters)));

	mModel->setHeaderData(0, Qt::Horizontal, tr("Filter"));
	mModel->setHeaderData(1, Qt::Horizontal, tr("Browse"));
	mModel->setHeaderData(2, Qt::Horizontal, tr("Register"));

	QTableView* filterTableView = new QTableView(this);
	filterTableView->setModel(mModel);
	filterTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
	filterTableView->verticalHeader()->hide();
	//filterTableView->horizontalHeader()->hide();
	filterTableView->setShowGrid(false);
	filterTableView->resizeColumnsToContents();
	filterTableView->resizeRowsToContents();
	filterTableView->setWordWrap(false);

	QPushButton* openDefault = new QPushButton(tr("Set as Default Viewer"), this);
	openDefault->setObjectName("openDefault");

	// now the final widgets
	QVBoxLayout* layout = new QVBoxLayout(this);
	layout->addWidget(filterTableView);

#ifdef Q_OS_WIN
	layout->addWidget(openDefault);
#else
	openDefault->hide();
#endif

}
开发者ID:Messna,项目名称:nomacs,代码行数:37,代码来源:DkPreferenceWidgets.cpp

示例14: 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();
    }
}
开发者ID:youngjeff,项目名称:qt,代码行数:36,代码来源:widget.cpp

示例15: getSpeciesList

bool DatabaseHandler::getSpeciesList(QString type, QComboBox * cmb_box) {
	qDebug() << "Populating species list for " << type;
    QString qstr = "SELECT name_de, name_lat, euring_id, length FROM taxa LEFT JOIN "
    		"(SELECT id_code, to_char(avg(length), 'FM99.99') as length FROM census WHERE tp='%1' GROUP BY id_code) as lt ON taxa.euring_id = lt.id_code "
    		"WHERE type='%1' ORDER BY seaflag DESC, name_de";
	QSqlQueryModel * model = new QSqlQueryModel;
	model->setQuery(qstr.arg(type));
	qDebug() << qstr.arg(type);
	model->setHeaderData(0, Qt::Horizontal, "Deutscher Name");
	model->setHeaderData(1, Qt::Horizontal, "Wissenschaftlicher Name");
	model->setHeaderData(2, Qt::Horizontal, "EURING Code");
	model->setHeaderData(3, Qt::Horizontal, QString::fromUtf8("Länge"));
	cmb_box->setModel(model);
	QTableView * view = new QTableView;
	cmb_box->setView(view);
	view->verticalHeader()->hide();
	view->hideColumn(2);
	view->resizeColumnsToContents();
	view->setSelectionMode(QAbstractItemView::SingleSelection);
	view->setSelectionBehavior(QAbstractItemView::SelectRows);
	view->setMinimumWidth(view->horizontalHeader()->length());

	return true;
}
开发者ID:ifaoe,项目名称:2014-10-Bird-View,代码行数:24,代码来源:DatabaseHandler.cpp


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