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); }
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"))); }
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(); }
// 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; }
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(); } }
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())); }
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()); }
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; }
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(); } }
FenetreGraphique::FenetreGraphique(QWidget* parent): QWidget(parent){ //Fentre principale this->setWindowTitle(QString("Project Calendar")); //setFixedSize(1200,800); setFixedSize(900,600); //qApp->setStyleSheet("QTableView{border:1px solid red;}"); //Onglets saisie et affichage onglets = new QTabWidget(this); //onglets->setGeometry(10,10,1180,780); onglets->setGeometry(10,10,980,540); pageSaisie = new QWidget; pageAffichage = new QWidget; pageExport = new QWidget; //Page Saisie////////////////////////////////////////////////////////////////////////////////////////////// layoutPageSaisiePrincipal = new QHBoxLayout; //GroupBox selectionprojet + treeview layoutProjetTV = new QVBoxLayout; gBProjetTV = new QGroupBox(this); gBProjetTV->setTitle("Projets"); gBProjetTV->setFixedWidth(300); //onglets creation projet, tache, event supportOngletsCreation = new QWidget; ongletsNiveau2 = new QTabWidget(supportOngletsCreation); ongletsNiveau2->setGeometry(0,10,540,420); //ongletsNiveau2->setGeometry(0,10,840,720); pageCreationprojet = new QWidget; pageTacheUnitaire = new QWidget; pageTacheComposite = new QWidget; initialisationTabPTUTC(); //Liste des projets bNouveauProjet = new QPushButton("Nouveau projet"); menuDeroulantProjets = new QComboBox; initialisationMenuProjet(); //Treeview modelTreeView = new QStandardItemModel; vueTreeView = new QTreeView; vueTreeView->setModel(modelTreeView); vueTreeView->setHeaderHidden(true); vueTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers); //creation projets layoutCreationProjet1 = new QHBoxLayout; layoutCreationProjet2 = new QHBoxLayout; layoutCreationProjet3 = new QHBoxLayout; layoutCreationProjet4 = new QHBoxLayout; layoutCreationProjet5 = new QHBoxLayout; layoutCreationProjet = new QVBoxLayout; labelNomProjet = new QLabel("Nom du projet :"); nomProjet = new QLabel(""); labelProjetDateDispo = new QLabel("Date de disponibilité : "); projetDateDispo = new QLabel(""); labelProjetEcheance = new QLabel("Echéance du projet :"); projetEcheance = new QLabel(""); bCreerTacheUProjet = new QPushButton("Creer tache unitaire"); bCreerTacheCProjet = new QPushButton("Creer tache composite"); bModifierProjet = new QPushButton("Modifier le projet"); bdetruireProjet = new QPushButton("Supprimer"); //creation tache layoutCreationTache1 = new QHBoxLayout; layoutCreationTache2 = new QHBoxLayout; layoutCreationTache3 = new QHBoxLayout; layoutCreationTache4 = new QHBoxLayout; layoutCreationTache5 = new QHBoxLayout; layoutCreationTache6 = new QHBoxLayout; layoutCreationTache7 = new QHBoxLayout; layoutCreationTache8 = new QHBoxLayout; layoutCreationTache = new QVBoxLayout; //Fenetre TacheUnitaire labelIdentificateurTache = new QLabel("Identificateur de la tache : "); identificateurTache = new QLabel(""); preemptiveTache = new QCheckBox("Preemptive"); preemptiveTache->setDisabled(true); titreTacheLabel = new QLabel("Titre de la tache :"); titreTache = new QLabel(""); labelTacheEtat = new QLabel("Etat :"); tacheEtat = new QLabel(""); labelDisponibiliteTache = new QLabel("Date de disponibilité :"); disponibiliteTache = new QLabel(""); labelTacheEcheance = new QLabel("Date d'écheance :"); tacheEcheance = new QLabel(""); labelTacheDuree = new QLabel("Durée :"); tacheDuree = new QLabel(""); labelPrecedenceTacheU = new QLabel("Tâches précédentes"); modelePrecedenceTacheU = new QStringListModel(QStringList("")); vuePrecedenceTacheU = new QListView; vuePrecedenceTacheU->setModel(modelePrecedenceTacheU); vuePrecedenceTacheU->setEditTriggers(QAbstractItemView::NoEditTriggers); bModifierTacheU = new QPushButton("Modifier"); bSupprimerTacheU = new QPushButton("Supprimer"); //creation Event layoutCreationEvent1 = new QHBoxLayout; layoutCreationEvent2 = new QHBoxLayout; layoutCreationEvent3 = new QHBoxLayout; layoutCreationEvent4 = new QHBoxLayout; layoutCreationEvent5 = new QHBoxLayout; layoutCreationEvent6 = new QHBoxLayout; layoutCreationEvent7 = new QHBoxLayout; layoutCreationEvent8 = new QHBoxLayout; layoutCreationEvent9 = new QHBoxLayout; layoutCreationEvent = new QVBoxLayout; //Fenetre Tache Composite labelIdentificateurTacheC = new QLabel("Identificateur de la tache : "); identificateurTacheC = new QLabel(""); titreTacheLabelC = new QLabel("Titre de la tache"); titreTacheC = new QLabel(""); labelTacheEtatC = new QLabel("Etat :"); tacheEtatC = new QLabel(""); labelDisponibiliteTacheC = new QLabel("Date de disponibilité :"); disponibiliteTacheC = new QLabel(""); labelTacheCEcheance = new QLabel("Date d'écheance :"); tacheCEcheance = new QLabel(""); labelTacheCDuree = new QLabel("Durée totale:"); tacheCDuree = new QLabel(""); labelPrecedenceTacheC = new QLabel("Tâches précédentes"); modelePrecedenceTacheC = new QStringListModel(QStringList("")); vuePrecedenceTacheC = new QListView; vuePrecedenceTacheC->setModel(modelePrecedenceTacheC); vuePrecedenceTacheC->setEditTriggers(QAbstractItemView::NoEditTriggers); bTacheCCreerTacheU = new QPushButton("Creer sous tâche unitaire"); bTacheCCreerTacheC = new QPushButton("Creer sous tâche composite"); bModifierTacheC = new QPushButton("Modifier"); bSupprimerTacheC = new QPushButton("Supprimer"); //Imbrication projets + treeview layoutProjetTV->addWidget(bNouveauProjet); layoutProjetTV->addWidget(menuDeroulantProjets); layoutProjetTV->addWidget(vueTreeView); gBProjetTV->setLayout(layoutProjetTV); //imbrication onglet creation projet layoutCreationProjet1->addWidget(labelNomProjet); layoutCreationProjet1->addWidget(nomProjet); layoutCreationProjet2->addWidget(labelProjetDateDispo); layoutCreationProjet2->addWidget(projetDateDispo); layoutCreationProjet3->addWidget(labelProjetEcheance); layoutCreationProjet3->addWidget(projetEcheance); layoutCreationProjet4->addWidget(bCreerTacheUProjet); layoutCreationProjet4->addWidget(bCreerTacheCProjet); layoutCreationProjet5->addWidget(bModifierProjet); layoutCreationProjet5->addWidget(bdetruireProjet); layoutCreationProjet->addLayout(layoutCreationProjet1); layoutCreationProjet->addLayout(layoutCreationProjet2); layoutCreationProjet->addLayout(layoutCreationProjet3); layoutCreationProjet->addLayout(layoutCreationProjet4); layoutCreationProjet->addLayout(layoutCreationProjet5); pageCreationprojet->setLayout(layoutCreationProjet); //imbrication creation tache layoutCreationTache1->addWidget(labelIdentificateurTache); layoutCreationTache1->addWidget(identificateurTache); layoutCreationTache1->addWidget(preemptiveTache); layoutCreationTache2->addWidget(titreTacheLabel); layoutCreationTache2->addWidget(titreTache); layoutCreationTache3->addWidget(labelTacheEtat); layoutCreationTache3->addWidget(tacheEtat); layoutCreationTache4->addWidget(labelDisponibiliteTache); layoutCreationTache4->addWidget(disponibiliteTache); layoutCreationTache5->addWidget(labelTacheEcheance); layoutCreationTache5->addWidget(tacheEcheance); layoutCreationTache6->addWidget(labelTacheDuree); layoutCreationTache6->addWidget(tacheDuree); layoutCreationTache7->addWidget(labelPrecedenceTacheU); layoutCreationTache7->addWidget(vuePrecedenceTacheU); layoutCreationTache8->addWidget(bModifierTacheU); layoutCreationTache8->addWidget(bSupprimerTacheU); layoutCreationTache->addLayout(layoutCreationTache1); layoutCreationTache->addLayout(layoutCreationTache2); layoutCreationTache->addLayout(layoutCreationTache3); layoutCreationTache->addLayout(layoutCreationTache4); layoutCreationTache->addLayout(layoutCreationTache5); layoutCreationTache->addLayout(layoutCreationTache6); layoutCreationTache->addLayout(layoutCreationTache7); layoutCreationTache->addLayout(layoutCreationTache8); pageTacheUnitaire->setLayout(layoutCreationTache); //imbrication creation Event layoutCreationEvent1->addWidget(labelIdentificateurTacheC); layoutCreationEvent1->addWidget(identificateurTacheC); layoutCreationEvent2->addWidget(titreTacheLabelC); layoutCreationEvent2->addWidget(titreTacheC); layoutCreationEvent3->addWidget(labelTacheEtatC); layoutCreationEvent3->addWidget(tacheEtatC); layoutCreationEvent4->addWidget(labelDisponibiliteTacheC); layoutCreationEvent4->addWidget(disponibiliteTacheC); layoutCreationEvent5->addWidget(labelTacheCEcheance); layoutCreationEvent5->addWidget(tacheCEcheance); layoutCreationEvent6->addWidget(labelTacheCDuree); layoutCreationEvent6->addWidget(tacheCDuree); layoutCreationEvent7->addWidget(labelPrecedenceTacheC); layoutCreationEvent7->addWidget(vuePrecedenceTacheC); layoutCreationEvent8->addWidget(bTacheCCreerTacheU); layoutCreationEvent8->addWidget(bTacheCCreerTacheC); layoutCreationEvent9->addWidget(bModifierTacheC); layoutCreationEvent9->addWidget(bSupprimerTacheC); layoutCreationEvent->addLayout(layoutCreationEvent1); layoutCreationEvent->addLayout(layoutCreationEvent2); layoutCreationEvent->addLayout(layoutCreationEvent3); layoutCreationEvent->addLayout(layoutCreationEvent4); layoutCreationEvent->addLayout(layoutCreationEvent5); layoutCreationEvent->addLayout(layoutCreationEvent6); layoutCreationEvent->addLayout(layoutCreationEvent7); layoutCreationEvent->addLayout(layoutCreationEvent8); layoutCreationEvent->addLayout(layoutCreationEvent9); pageTacheComposite->setLayout(layoutCreationEvent); //imbrication onglets niveau2 + layout principal pageSaisie ongletsNiveau2->addTab(pageCreationprojet, "Projet"); ongletsNiveau2->addTab(pageTacheUnitaire, "Tâche unitaire"); ongletsNiveau2->addTab(pageTacheComposite, "Tâche composite"); layoutPageSaisiePrincipal->addWidget(gBProjetTV); layoutPageSaisiePrincipal->addWidget(supportOngletsCreation); //page Affichage///////////////////////////////////////////////////////////////////////////////////////////////////// layoutPageAffichagePrincipal = new QVBoxLayout; //En tete (gestion semaine suivante/precedente layoutHautAgenda = new QHBoxLayout; dateReferenceAgenda = new QDate(QDate::currentDate()); jourActuel = new QPushButton(constructionMessageSemaineAgenda(dateReferenceAgenda)); jourActuel->setEnabled(false); bSemainePrecedente = new QPushButton("Semaine precedent"); bSemaineSuivante = new QPushButton("Semaine suivant"); layoutHautAgenda->addWidget(bSemainePrecedente); layoutHautAgenda->addWidget(jourActuel); layoutHautAgenda->addWidget(bSemaineSuivante); QStandardItemModel *modelAgenda = new QStandardItemModel(60, 7); QTableView *vueAgenda = new QTableView; vueAgenda->setEditTriggers(QAbstractItemView::NoEditTriggers); vueAgenda->setModel(modelAgenda); vueAgenda->setFixedWidth(1157); vueAgenda->setFixedHeight(625); vueAgenda->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); vueAgenda->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); vueAgenda->setSelectionMode(QAbstractItemView::SingleSelection); //=========== vueAgenda->setGridStyle(Qt::DashDotLine); miseAJourTableau(*modelAgenda); //, *vueAgenda); itemCol0 = new QStandardItem(chaineJoursHeader(1, dateReferenceAgenda->addDays(1-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); itemCol1 = new QStandardItem(chaineJoursHeader(2, dateReferenceAgenda->addDays(2-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); itemCol2 = new QStandardItem(chaineJoursHeader(3, dateReferenceAgenda->addDays(3-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); itemCol3 = new QStandardItem(chaineJoursHeader(4, dateReferenceAgenda->addDays(4-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); itemCol4 = new QStandardItem(chaineJoursHeader(5, dateReferenceAgenda->addDays(5-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); itemCol5 = new QStandardItem(chaineJoursHeader(6, dateReferenceAgenda->addDays(6-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); itemCol6 = new QStandardItem(chaineJoursHeader(7, dateReferenceAgenda->addDays(7-dateReferenceAgenda->dayOfWeek()).day(), dateReferenceAgenda->month())); modelAgenda->setHorizontalHeaderItem(0, itemCol0); modelAgenda->setHorizontalHeaderItem(1, itemCol1); modelAgenda->setHorizontalHeaderItem(2, itemCol2); modelAgenda->setHorizontalHeaderItem(3, itemCol3); modelAgenda->setHorizontalHeaderItem(4, itemCol4); modelAgenda->setHorizontalHeaderItem(5, itemCol5); modelAgenda->setHorizontalHeaderItem(6, itemCol6); QStringList headerVTableau; for(unsigned int i=7; i<22; i++) { headerVTableau << QString::number(i)+"h00"; for(unsigned int j=1; j<4; j++) { headerVTableau << ""; //headerVTableau << QString::number(j*15); } } modelAgenda->setVerticalHeaderLabels(headerVTableau); miseEnFormeLigneColonnes(vueAgenda); //bas de page (programmation) layoutProgrammation = new QHBoxLayout; bProgrammerTache = new QPushButton("Programmer tâche"); bProgrammerEvt = new QPushButton("Programmer Evenement"); bSupprimerProgrammation = new QPushButton("Supprimer programmation"); layoutProgrammation->addWidget(bProgrammerTache); layoutProgrammation->addWidget(bProgrammerEvt); layoutProgrammation->addWidget(bSupprimerProgrammation); //pose des layouts pageAffichage layoutPageAffichagePrincipal->addLayout(layoutHautAgenda); layoutPageAffichagePrincipal->addWidget(vueAgenda); layoutPageAffichagePrincipal->addLayout(layoutProgrammation); //pageExport///////////////////////////////////////////////////////////////////////////////////////////////////// layoutPageExportPrincipal = new QHBoxLayout; widgetSecondairePageExport = new QWidget; widgetSecondairePageExport->setFixedSize(400, 300); layoutPageExportSecondaire = new QVBoxLayout(widgetSecondairePageExport); labelExport = new QLabel("Chosir le type d'export:"); nomFichierExport = new QLineEdit("NomFichier"); bExportImport = new QPushButton("Importer"); bExportImport->setEnabled(false); bExportProgrammationBrut = new QPushButton("Programmation totale (brut)"); bExportProgrammationXml = new QPushButton("Programmation totale (Xml"); bExportSemaineBrut = new QPushButton("Programmation semaine (brut)"); bExportSemaineXml = new QPushButton("Programmation semaine (Xml)"); //pose des layout page export layoutPageExportSecondaire->addWidget(labelExport); layoutPageExportSecondaire->addWidget(nomFichierExport); layoutPageExportSecondaire->addWidget(bExportImport); layoutPageExportSecondaire->addWidget(bExportProgrammationBrut); layoutPageExportSecondaire->addWidget(bExportProgrammationXml); layoutPageExportSecondaire->addWidget(bExportSemaineBrut); layoutPageExportSecondaire->addWidget(bExportSemaineXml); layoutPageExportPrincipal->addWidget(widgetSecondairePageExport); //pose des layouts principaux pageAffichage->setLayout(layoutPageAffichagePrincipal); pageSaisie->setLayout(layoutPageSaisiePrincipal); pageExport->setLayout(layoutPageExportPrincipal); onglets->addTab(pageAffichage, "Agenda"); onglets->addTab(pageSaisie, "Gestionnaire de projet"); onglets->addTab(pageExport, "Exports"); //connections page saisie------------- QObject::connect(vueAgenda, SIGNAL(doubleClicked(const QModelIndex)), this, SLOT(affichageContenuCase(const QModelIndex))); QObject::connect(bSemainePrecedente, SIGNAL(clicked()), this, SLOT(semainePrecedente())); QObject::connect(bSemaineSuivante, SIGNAL(clicked()), this, SLOT(semaineSuivante())); QObject::connect(bProgrammerTache, SIGNAL(clicked()), this, SLOT(nouvelleProgrammationTache())); QObject::connect(bProgrammerEvt, SIGNAL(clicked()), this, SLOT(nouvelleProgrammationEvt())); QObject::connect(bSupprimerProgrammation, SIGNAL(clicked()), this, SLOT(supprimerProgrammation())); //connexions page affichage---------- //tree view QObject::connect(menuDeroulantProjets, SIGNAL(currentIndexChanged(int)), this, SLOT(changerProjetTreeView(int))); QObject::connect(vueTreeView, SIGNAL(clicked(const QModelIndex)), this, SLOT(selectionTreeView(const QModelIndex))); //Creation projet, tache, evenement QObject::connect(bNouveauProjet, SIGNAL(clicked()), this, SLOT(creerProjet())); QObject::connect(bCreerTacheUProjet, SIGNAL(clicked()), this, SLOT(creerTacheUProjet())); QObject::connect(bCreerTacheCProjet, SIGNAL(clicked()), this, SLOT(creerTacheCProjet())); QObject::connect(bModifierProjet, SIGNAL(clicked()), this, SLOT(modifierProjet())); QObject::connect(bdetruireProjet, SIGNAL(clicked()), this, SLOT(detruireProjet())); QObject::connect(bModifierTacheU, SIGNAL(clicked()), this, SLOT(modifierTacheU())); QObject::connect(bSupprimerTacheU, SIGNAL(clicked()), this, SLOT(supprimerTacheU())); QObject::connect(bTacheCCreerTacheU, SIGNAL(clicked()), this, SLOT(creerTacheUTacheC())); QObject::connect(bTacheCCreerTacheC, SIGNAL(clicked()), this, SLOT(creerTacheCTacheC())); QObject::connect(bModifierTacheC, SIGNAL(clicked()), this, SLOT(modifierTacheC())); QObject::connect(bSupprimerTacheC, SIGNAL(clicked()), this, SLOT(supprimerTacheC())); //connexions page export-------------- QObject::connect(nomFichierExport, SIGNAL(textEdited(QString)), this, SLOT(validationNomExport(QString))); QObject::connect(bExportProgrammationBrut, SIGNAL(clicked()), this, SLOT(exportProgrammationBrut())); QObject::connect(bExportProgrammationXml, SIGNAL(clicked()), this, SLOT(exportProgrammationXml())); QObject::connect(bExportSemaineBrut, SIGNAL(clicked()), this, SLOT(exportSemaineBrut())); QObject::connect(bExportSemaineXml, SIGNAL(clicked()), this, SLOT(exportSemaineXml())); }
void PrintLayout::printTable() { // create and setup a table QTableView table; table.setAttribute(Qt::WA_DontShowOnScreen); table.setSelectionMode(QAbstractItemView::NoSelection); table.setFocusPolicy(Qt::NoFocus); table.horizontalHeader()->setVisible(false); table.horizontalHeader()->setResizeMode(QHeaderView::Fixed); table.verticalHeader()->setVisible(false); table.verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // fit table to one page initially table.resize(scaledPageW, scaledPageH); // create and fill a table model TablePrintModel model; struct dive *dive; int i, row = 0; addTablePrintHeadingRow(&model, row); // add one heading row row++; for_each_dive(i, dive) { if (!dive->selected && printOptions->print_selected) continue; addTablePrintDataRow(&model, row, dive); row++; } table.setModel(&model); // set model to table // resize columns to percentages from page width for (int i = 0; i < model.columns; i++) { int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100); table.horizontalHeader()->resizeSection(i, pw); } // reset the model at this point model.callReset(); // a list of vertical offsets where pages begin and some helpers QList<unsigned int> pageIndexes; pageIndexes.append(0); int tableHeight = 0, rowH = 0, accH = 0; // process all rows for (int i = 0; i < model.rows; i++) { rowH = table.rowHeight(i); accH += rowH; if (accH > scaledPageH) { // push a new page index and add a heading pageIndexes.append(pageIndexes.last() + (accH - rowH)); addTablePrintHeadingRow(&model, i); accH = 0; i--; } tableHeight += rowH; } pageIndexes.append(pageIndexes.last() + accH); // resize the whole widget so that it can be rendered table.resize(scaledPageW, tableHeight); // attach a painter and render pages by using pageIndexes QPainter painter(printer); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.scale(scaleX, scaleY); for (int i = 0; i < pageIndexes.size() - 1; i++) { if (i > 0) printer->newPage(); QRegion region(0, pageIndexes.at(i) - 1, table.width(), pageIndexes.at(i + 1) - pageIndexes.at(i) + 2); table.render(&painter, QPoint(0, 0), region); } }
int main(int argc, char *argv[]) { QApplication app(argc, argv); // ![0] QStandardItemModel model(0, 1); populateListModel(&model); // ![0] QWidget toplevel; QVBoxLayout *layout = new QVBoxLayout(&toplevel); // ![1] QMaemo5ValueButton *button1 = new QMaemo5ValueButton("Value besides text"); button1->setValueLayout(QMaemo5ValueButton::ValueBesideText); QMaemo5ListPickSelector *selector1 = new QMaemo5ListPickSelector; selector1->setModel(&model); // not setting the current index means that the value is empty. button1->setPickSelector(selector1); // ![1] // ![2] QStandardItemModel tableModel(0, 0); populateTableModel(&tableModel); // ![2] // ![3] QMaemo5ValueButton *button2 = new QMaemo5ValueButton("Value under text"); button2->setValueLayout(QMaemo5ValueButton::ValueUnderText); QMaemo5ListPickSelector *selector2 = new QMaemo5ListPickSelector; selector2->setModel(&tableModel); selector2->setModelColumn(2); selector2->setCurrentIndex(5); button2->setPickSelector(selector2); // ![3] // create a custom view we want a table view instead of a list QTableView *view = new QTableView(); view->setEditTriggers(QAbstractItemView::NoEditTriggers); // try to get a sensible column width and row height view->setModel(&tableModel); // set the model in order to get correct column widths view->resizeColumnsToContents(); view->resizeRowsToContents(); view->horizontalHeader()->setStretchLastSection(true); view->verticalHeader()->setVisible(false); view->horizontalHeader()->setVisible(false); view->setSelectionBehavior(QAbstractItemView::SelectRows); view->setSelectionMode(QAbstractItemView::SingleSelection); // five rows should be visible as a default if (view->verticalHeader()->sectionSize(0)>0) view->setMinimumHeight(view->verticalHeader()->sectionSize(0) * 5); QMaemo5ValueButton *button3 = new QMaemo5ValueButton("Value centered under text"); button3->setValueLayout(QMaemo5ValueButton::ValueUnderTextCentered); QMaemo5ListPickSelector *selector3 = new QMaemo5ListPickSelector; selector3->setModel(&tableModel); selector3->setModelColumn(2); selector3->setView(view); // set our new custom view selector3->setCurrentIndex(0); button3->setPickSelector(selector3); layout->addWidget(button1); layout->addWidget(button2); layout->addWidget(button3); toplevel.show(); return app.exec(); }
void PrintLayout::printTable() { struct dive *dive; int done = 0; // percents done int i, row = 0, progress, total = estimateTotalDives(); if (!total) return; // create and setup a table QTableView table; table.setAttribute(Qt::WA_DontShowOnScreen); table.setSelectionMode(QAbstractItemView::NoSelection); table.setFocusPolicy(Qt::NoFocus); table.horizontalHeader()->setVisible(false); table.verticalHeader()->setVisible(false); #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) table.horizontalHeader()->setResizeMode(QHeaderView::Fixed); table.verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); #else table.horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); table.verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); #endif table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // fit table to one page initially table.resize(scaledPageW, scaledPageH); // don't show border table.setStyleSheet( "QTableView { border: none }"); // create and fill a table model TablePrintModel model; addTablePrintHeadingRow(&model, row); // add one heading row row++; progress = 0; for_each_dive(i, dive) { if (!dive->selected && printOptions->print_selected) continue; addTablePrintDataRow(&model, row, dive); row++; progress++; emit signalProgress((progress * 10) / total); } done = 10; table.setModel(&model); // set model to table // resize columns to percentages from page width int accW = 0; int cols = model.columns; int tableW = table.width(); for (i = 0; i < model.columns; i++) { int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100.0); accW += pw; if (i == cols - 1 && accW > tableW) /* adjust last column */ pw -= accW - tableW; table.horizontalHeader()->resizeSection(i, pw); } // reset the model at this point model.callReset(); // a list of vertical offsets where pages begin and some helpers QList<unsigned int> pageIndexes; pageIndexes.append(0); /* the algorithm bellow processes the table rows in multiple passes, * compensating for loss of space due to moving rows on a new page instead * of truncating them. * there is a 'passes' array defining how much percents of the total * progress each will take. given, the first and last stage of this function * use 10% each, then the sum of passes[] here should be 80%. * two should be enough! */ const int passes[] = { 70, 10 }; int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings; bool isHeading = false; for (unsigned int pass = 0; pass < sizeof(passes) / sizeof(passes[0]); pass++) { progress = headings = accH = 0; total = model.rows - lastAccIndex; for (i = lastAccIndex; i < model.rows; i++) { rowH = table.rowHeight(i); accH += rowH; if (isHeading) { headings += rowH; isHeading = false; } if (accH > scaledPageH) { lastAccIndex = i; pageIndexes.append(pageIndexes.last() + (accH - rowH)); addTablePrintHeadingRow(&model, i); isHeading = true; accH = 0; i--; } tableHeight += table.rowHeight(i); progress++; emit signalProgress(done + (progress * passes[pass]) / total); } done += passes[pass]; } done = 90; pageIndexes.append(pageIndexes.last() + accH + headings); table.resize(scaledPageW, tableHeight); // attach a painter and render pages by using pageIndexes QPainter painter(printer); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.scale(scaleX, scaleY); total = pageIndexes.size() - 1; progress = 0; for (i = 0; i < total; i++) { if (i > 0) printer->newPage(); QRegion region(0, pageIndexes.at(i) - 1, table.width(), pageIndexes.at(i + 1) - pageIndexes.at(i) + 1); table.render(&painter, QPoint(0, 0), region); progress++; emit signalProgress(done + (progress * 10) / total); } }
/* 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; }