int main(int argc, char *argv[]) { QApplication a(argc, argv); QListView *listView = new QListView; QListView *newListView = new QListView; QStringList nameItem; nameItem << "Linux" << "Android" << "Mac OS"; QStandardItemModel *model = new QStandardItemModel(nameItem.length(),1); // initialize row and columns of data model for(int i = 0; i < model->rowCount(); ++i) { QModelIndex modelIndex = model->index(i,0); QString str = nameItem.at(i); model->setData(modelIndex,str,Qt::DisplayRole); model->setData(modelIndex,"ToolTip for" + str,Qt::ToolTipRole); model->setData(modelIndex,QIcon(":/Images/" + str + ".jpeg"),Qt::DecorationRole); } listView->setViewMode(QListView::IconMode); listView->setModel(model); listView->setGeometry(430,340,200,200); newListView->setViewMode(QListView::IconMode); newListView->setModel(model); newListView->setGeometry(listView->geometry()); listView->show(); newListView->show(); return a.exec(); }
void tst_QItemDelegate::task257859_finalizeEdit() { QStandardItemModel model; model.appendRow(new QStandardItem()); QListView view; view.setModel(&model); view.show(); QApplication::setActiveWindow(&view); view.setFocus(); QTest::qWait(30); QModelIndex index = model.index(0, 0); view.edit(index); QTest::qWait(30); QList<QLineEdit *> lineEditors = qFindChildren<QLineEdit *>(view.viewport()); QCOMPARE(lineEditors.count(), 1); QPointer<QWidget> editor = lineEditors.at(0); QCOMPARE(editor->hasFocus(), true); QDialog dialog; QTimer::singleShot(500, &dialog, SLOT(close())); dialog.exec(); QTRY_VERIFY(!editor); }
void tst_QItemDelegate::doubleEditorNegativeInput() { QStandardItemModel model; QStandardItem *item = new QStandardItem; item->setData(10.0, Qt::DisplayRole); model.appendRow(item); QListView view; view.setModel(&model); view.show(); QModelIndex index = model.index(0, 0); view.setCurrentIndex(index); // the editor will only selectAll on the current index view.edit(index); QList<QDoubleSpinBox*> editors = qFindChildren<QDoubleSpinBox *>(view.viewport()); QCOMPARE(editors.count(), 1); QDoubleSpinBox *editor = editors.at(0); QCOMPARE(editor->value(), double(10)); QTest::keyClick(editor, Qt::Key_Minus); QTest::keyClick(editor, Qt::Key_1); QTest::keyClick(editor, Qt::Key_0); QTest::keyClick(editor, Qt::Key_Comma); //support both , and . locales QTest::keyClick(editor, Qt::Key_Period); QTest::keyClick(editor, Qt::Key_0); QTest::keyClick(editor, Qt::Key_Enter); QApplication::processEvents(); QCOMPARE(index.data().toString(), QString("-10")); }
void MainWindow::buildFileBrowser() { QString rootPath = qgetenv("HOME"); this->drivesModel->setFilter(QDir::NoDotAndDotDot | QDir::Dirs); QTreeView *treeView = this->treeView = new QTreeView(this->ui->dockDir); treeView->setModel(this->drivesModel); treeView->setRootIndex(this->drivesModel->setRootPath(rootPath + "/../")); treeView->hideColumn(1); treeView->hideColumn(2); treeView->hideColumn(3); treeView->setEditTriggers(QAbstractItemView::NoEditTriggers); treeView->setDragEnabled(true); treeView->setDragDropMode(QAbstractItemView::DragOnly); this->ui->dockDir->setWidget(treeView); this->filesModel->setFilter(QDir::NoDotAndDotDot | QDir::Files); QListView *listView = this->listView = new QListView(this->ui->dockFile); listView->setModel(this->filesModel); listView->setRootIndex(this->filesModel->setRootPath(rootPath)); listView->setEditTriggers(QAbstractItemView::NoEditTriggers); listView->setDragEnabled(true); listView->setSelectionMode(QAbstractItemView::ExtendedSelection); this->ui->dockFile->setWidget(listView); listView->show(); treeView->show(); }
int main( int argc, char* argv[] ){ if(argc != 2){ return std::cerr<<"No!"<<std::endl; } QApplication a(argc,argv); std::ifstream file; file.open(argv[1]); std::string line; std::string alltext; while(getline(file, line)){ alltext += line; alltext += "\n"; } file.close(); QString filetext(QString::fromStdString(alltext)); DnDAddressModel model(filetext); QListView listView; listView.setModel(&model); listView.setModelColumn(0); listView.show(); QTreeView treeView; treeView.setModel(&model); treeView.show(); QTableView tableView; tableView.setModel(&model); tableView.show(); return a.exec(); }
//! [0] int main(int argc, char *argv[]) { QApplication app(argc, argv); // Unindented for quoting purposes: //! [1] QStringList numbers; numbers << "One" << "Two" << "Three" << "Four" << "Five"; QAbstractItemModel *model = new StringListModel(numbers); //! [0] //! [1] //! [2] //! [3] QListView *view = new QListView; //! [2] view->setWindowTitle("View onto a string list model"); //! [4] view->setModel(model); //! [3] //! [4] model->insertRows(5, 7, QModelIndex()); for (int row = 5; row < 12; ++row) { QModelIndex index = model->index(row, 0, QModelIndex()); model->setData(index, QString::number(row+1)); } //! [5] view->show(); return app.exec(); }
int main( int argc, char* argv[] ) { QApplication app( argc, argv ); // Open the addressbook file in the working directory QFile file("addressbook.csv"); if ( !file.open(QIODevice::ReadOnly|QIODevice::Text) ) return 1; // Read its content into a string QString addresses = QString::fromUtf8(file.readAll()); AddressbookModel model(addresses); QListView listView; listView.setModel(&model); listView.setModelColumn(0); listView.show(); QTreeView treeView; treeView.setModel(&model); treeView.show(); QTableView tableView; tableView.setModel(&model); tableView.show(); return app.exec(); }
void tst_QItemDelegate::editorKeyPress() { QFETCH(QString, initial); QFETCH(QString, expected); QStandardItemModel model; model.appendRow(new QStandardItem(initial)); QListView view; view.setModel(&model); view.show(); QModelIndex index = model.index(0, 0); view.setCurrentIndex(index); // the editor will only selectAll on the current index view.edit(index); QList<QLineEdit*> lineEditors = qFindChildren<QLineEdit *>(view.viewport()); QCOMPARE(lineEditors.count(), 1); QLineEdit *editor = lineEditors.at(0); QCOMPARE(editor->selectedText(), initial); QTest::keyClicks(editor, expected); QTest::keyClick(editor, Qt::Key_Enter); QApplication::processEvents(); QCOMPARE(index.data().toString(), expected); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); // 创建文件系统模型 QFileSystemModel model; // 指定要监视的目录 model.setRootPath(QDir::currentPath()); // 创建树型视图 QTreeView tree; // 为视图指定模型 tree.setModel(&model); // 指定根索引 tree.setRootIndex(model.index(QDir::currentPath())); // 创建列表视图 QListView list; list.setModel(&model); list.setRootIndex(model.index(QDir::currentPath())); tree.show(); list.show(); return app.exec(); }
int main(int c, char **v) { QApplication a(c, v); QListView view; view.setUniformItemSizes(true); view.setModel(new RandomListModel(&view)); view.show(); return a.exec(); }
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow){ ui->setupUi(this); setWindowIcon(QIcon("/Users/nick102795/Desktop/favicon.ico")); // build all initial backend structures & load the appropriate data from files setInitialState(); // Set Up the top 8 Most Popular Playlists QListView *listView = ui->mostPopularPlaylistListView; QAbstractItemModel *model = buildModel(); // make the buildModel() func to intake the new most-popular PL strings listView->setModel(model); listView->show(); }
int main( int argc, char **argv ) { QApplication app( argc, argv ); IntModel model( 25 ); QListView list; list.setModel( &model ); list.show(); return app.exec(); }
int main(int argc, char* argv[]) { QApplication app(argc, argv); QStringListModel model; QStringList toBuy; toBuy << "butter" << "milk" << "cherries" << "bananas"; model.setStringList(toBuy); QListView view; view.setModel(&model); view.show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); app.setOrganizationName("CuteRadio"); app.setApplicationName("Genres"); CuteRadio::GenresModel model; QListView view; view.setModel(&model); view.setMinimumSize(QSize(500, 500)); model.reload(); view.show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QListView list; QStringListModel model; QStringList strings; strings << "Huey" << "Dewey" << "Louie"; model.setStringList(strings); list.setModel(&model); list.show(); return app.exec(); }
// single playlist adding void MainWindow::on_pushButton_3_clicked(){ ui->textEdit_3->setStyleSheet("color:black; background-color:white"); playlistName = ui->textEdit_3->toPlainText(); playlistPopularity = ui->textEdit_4->toPlainText(); string sPlaylistName = playlistName.toLatin1().data(); string sPlaylistPopularity = playlistPopularity.toLatin1().data(); //test single playlist input: Friend Of God, Your Great Name, Collide, September 63 bool is_legal_pop = true; bool is_legal_ss = is_legal_input_str_stream(sPlaylistName); int dec = playlistPopularity.toInt(&is_legal_pop, 10); // some general console error logs if(!is_legal_ss && !is_legal_pop){ std::cout << "illegal stream & illegal popularity inputs" << std::endl; } else if(!is_legal_ss){ std::cout << "illegal stream input" << std::endl; } else if(!is_legal_pop){ std::cout << "illegal popularity input" << std::endl; } if(is_legal_ss && is_legal_pop){ string song_id_stream = convTitleStream2StrNumStream(sPlaylistName); std::cout << "Single Playlist Submitted: " << (sPlaylistName + " " + sPlaylistPopularity) << std::endl; Playlist* new_pl = new Playlist(song_id_stream,playlistPopularity.toInt()); // add a new playlist pl_c->add(new_pl); // add this playlists popularity to the song's pop for(int ii = 0; ii < new_pl->my_songs->size(); ii++){ std::string member_song_id = new_pl->my_songs->at(ii); // sng_c->query(member_song_id)->set_song_popularity(sng_c->query(member_song_id)->getPopularity() + new_pl->getPopularity()); sng_c->query((member_song_id))->song_add_playlist(new_pl->my_id); } // refine is required to maintain the backend storage and so-on pl_c->refine(); QListView *listView = ui->mostPopularPlaylistListView; QAbstractItemModel *model = buildModel(); // make the buildModel() func to intake the new most-popular PL strings listView->setModel(model); listView->show(); } }
// ------------------------------------------------------------------------------ int ctkSearchBoxTest2(int argc, char* argv[]) { QApplication app(argc, argv); QStringList stringList; stringList<<"totoa"<<"TOTOaa"<<"tic"<<"tac"<<"nice"<<"slicer"<<"monday"<<"july"<<"phone"; ctkSearchBox search3; search3.show(); search3.setText("phone"); QRegExp regExp(search3.text(),Qt::CaseInsensitive, QRegExp::Wildcard); //QStringList testFilter = stringList.filter(search3.text()); QStringList testFilter = stringList.filter(regExp); qDebug() << "Result of Test Filter : " << testFilter; if (testFilter.size() >= stringList.size()) { qDebug() << "Line : " << __LINE__<< " error with the filter : " << search3.text(); } QStringListModel listModel(stringList); QSortFilterProxyModel filterModel; filterModel.setSourceModel(&listModel); filterModel.setFilterCaseSensitivity(Qt::CaseInsensitive); filterModel.setFilterWildcard(search3.text()); QObject::connect(&search3, SIGNAL(textChanged(QString)), &filterModel, SLOT(setFilterWildcard(QString))); QListView listView; listView.setModel(&filterModel); listView.show(); if (argc < 2 || QString(argv[1]) != "-I" ) { QTimer::singleShot(200, &app, SLOT(quit())); } return app.exec(); }
QtTutorial::QtTutorial(QWidget *parent) : QMainWindow(parent) { // ALL OF OUR VIEWS QListView *listView = new QListView(); listView->show(); QTreeView *treeView = new QTreeView(); treeView->show(); QComboBox *comboBox = new QComboBox(); comboBox->show(); QTableView *tableView = new QTableView(); tableView->show(); // RGBA QColor red = QColor(255, 0, 0, 255); QColor green = QColor(0, 255, 0, 255); QColor blue = QColor(0, 0, 255, 255); QList<QColor> items; items.append(red); items.append(green); items.append(blue); int rowCount = 4; int columnCount = 6; PaletteListModel *model = new PaletteListModel(items); // Insert at Position 3 -> 5 empty rows model->insertRows(3, 5); // Remove from position 4 -> 1 row // model->removeRows(4,1); listView->setModel(model); comboBox->setModel(model); tableView->setModel(model); treeView->setModel(model); }
int main(int argc, char **argv) { App::initializeDependencies(); K4AboutData about("tasklister", "tasklister", ki18n("Lists all the tasks"), "1.0"); KCmdLineArgs::init(argc, argv, &about); KApplication app; auto repository = Utils::DependencyManager::globalInstance().create<Domain::TaskRepository>(); auto queries = Utils::DependencyManager::globalInstance().create<Domain::TaskQueries>(); auto taskList = queries->findAll(); QListView view; view.setModel(new Presentation::TaskListModel(taskList, repository, &view)); view.resize(640, 480); view.show(); return app.exec(); }
int main(int argc, char * argv[]) { QApplication app(argc, argv); QTableView *table; QListView *list; // QStringListModel *model=new QStringListModel(QStringList()<<"qrty"<<"wy"); intListModel *model; model=new intListModel(QList<int>() << 0 << 1 << 2 << 3); table=new QTableView(); table->setModel(model); list=new QListView(); list->setModel(model); list->show(); table->show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); /*QLabel *id = new QLabel("Email or mobile phone"); QLineEdit *idLine = new QLineEdit; QLabel *password = new QLabel("Password"); QLineEdit *passwordLine = new QLineEdit; QPushButton *enter = new QPushButton("Enter"); QHBoxLayout *enterBox = new QHBoxLayout; //LoginScreenForm *form = new LoginScreenForm(id, idLine, password, passwordLine, enter, box, enterBox); //LoginScreen mainWindow(form);*/ QVBoxLayout *box = new QVBoxLayout; QWebView *view = new QWebView; QProgressBar *bar = new QProgressBar; WebLoginScreen scr(view, bar, box); scr.show(); requester req("6585056", "effe73b8de201068cc9a8819dac22d518f4e6a06e304d542c71f7af93f88fad2b44db86ff2ccc28b831ed"); req.getAudio("6585056"); QEventLoop wait; QTimer::singleShot(5000, &wait, SLOT(quit())); wait.exec(); qDebug() << "get Result " << req.getResult(); QByteArray array = req.getResult(); qDebug() << "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" << array; xmlParser prs; dataHolder* data = new dataHolder(prs.parseXML(array)); qDebug() << data->getObject(102).value("title").toString(); dataModel model(data); qDebug() << model.rowCount(); QListView list; list.setModel(&model); songsListDelegate *del = new songsListDelegate; list.setItemDelegate(del); list.show(); return app.exec(); }
int main(int argc, char **argv) { QApplication app(argc, argv); //QCoreApplication app(argc, argv); if(0) { ImageRecord rec("foobar.jpg"); rec.setImageId("abc"); ImageRecord::addRecord(&rec); qDebug() << "New Record:"<<rec; ImageRecord * rec2 = ImageRecord::retrieveImageId("abc"); qDebug() << "Record 'ABC':"<<rec2; } else if(0) { QListView * lv = new QListView; lv->setWindowTitle(IMAGEDB_FILE); lv->setModel(ImageRecordListModel::instance()); lv->show(); } else { ImageRecord * rec = ImageRecord::retrieve(99); //rec->setFile("test.jpg"); qDebug() << "Record#1: "<<rec; } // ImageRecord::db().close(); return -1; return app.exec(); }
int main( int argc, char** argv ) { QApplication app( argc, argv ); CityEngine *engine = new CityEngine(QCoreApplication::instance()); CityTableModel *model = new CityTableModel(QCoreApplication::instance()); model->setInput(engine); QListView* list = new QListView; list->setModel( model ); list->setWindowTitle( "QListView" ); list->show(); QTreeView* tree = new QTreeView; tree->setModel( model ); tree->setWindowTitle( "QTreeView" ); tree->show(); QTableView* table = new QTableView; table->setModel( model ); table->setWindowTitle( "QTableView" ); table->show(); return app.exec(); }
// upload playlists from a file void MainWindow::on_pushButton_2_clicked(){ QString fileName = ui->textEdit_2->toPlainText(); string sFileName = fileName.toLatin1().data(); std::cout << "Attempting to Upload: " + sFileName << std::endl; // test url: /Users/nick102795/Desktop/main/School/College/year3/EC504/playlist/uploads/day01.txt int line_counter = 1; QFile inputFile(fileName); if (inputFile.open(QIODevice::ReadOnly)){ QTextStream in(&inputFile); srand(time(NULL)); while (!in.atEnd()){ if(line_counter > 128){ // one is only allowed to upload 128 lines break; } QString line_temp = in.readLine(); string line = line_temp.toUtf8().constData(); string deliminator = " "; //make sure there is at least one '\t' on that line int up_to = line.find(deliminator); if(up_to <= 0){ // There is no tab deliminator to be found std::cout << "Tab Deliminator Error" << endl << "Exited due to error in the file." << endl <<"Successfully uploaded " << (line_counter - 1) << " playlists." << endl; break; } string str_of_song_ids = ""; for(int ii = 0; ii < up_to; ii++){ str_of_song_ids += line[ii]; } line = line.substr(line.find(deliminator)+1,line.length()-line.find(deliminator)+1); string pl_pop = line; int pl_popularity = atoi(pl_pop.c_str()); // was stoi but this version of C++ is bad std::cout << "Playlists Uploaded: " << (line_counter - 1) << std::endl; // std::cout << pl_pop << std::endl; if(!is_legal_id_stream(str_of_song_ids)){ std::cout << "Exited due to error in the file." << endl <<"Successfully uploaded " << (line_counter - 1) << " playlists." << endl; break; } // pl_popularity, str_of_song_ids are set at this point Playlist* new_pl = new Playlist(str_of_song_ids, pl_popularity); //std::cout << "ID: " << temp_str << " title: " << str_of_song_ids << " popularity: "<< pl_popularity << std::endl; pl_c->add(new_pl); // add this playlists popularity to the song's pop for(int ii = 0; ii < new_pl->my_songs->size(); ii++){ std::string member_song_id = new_pl->my_songs->at(ii); // sng_c->query(member_song_id)->set_song_popularity(sng_c->query(member_song_id)->getPopularity() + new_pl->getPopularity()); sng_c->query((member_song_id))->song_add_playlist(new_pl->my_id); } line_counter++; } pl_c->refine(); inputFile.close(); QListView *listView = ui->mostPopularPlaylistListView; QAbstractItemModel* model = buildModel(); // make the buildModel() func to intake the new most-popular PL strings listView->setModel(model); listView->show(); } else{ std::cout << "Failed to open: " << sFileName << std::endl; } ui->textEdit_2->setText(""); }
void tst_QItemDelegate::enterKey() { QFETCH(WidgetType, widget); QFETCH(int, key); QFETCH(bool, expectedFocus); QStandardItemModel model; model.appendRow(new QStandardItem()); QListView view; view.setModel(&model); view.show(); QApplication::setActiveWindow(&view); view.setFocus(); QTest::qWait(30); struct TestDelegate : public QItemDelegate { WidgetType widgetType; virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const { QWidget *editor = 0; switch(widgetType) { case LineEdit: editor = new QLineEdit(parent); break; case TextEdit: editor = new QTextEdit(parent); break; case PlainTextEdit: editor = new QPlainTextEdit(parent); break; } editor->setObjectName(QString::fromLatin1("TheEditor")); return editor; } } delegate; delegate.widgetType = widget; view.setItemDelegate(&delegate); QModelIndex index = model.index(0, 0); view.setCurrentIndex(index); // the editor will only selectAll on the current index view.edit(index); QTest::qWait(30); QList<QWidget*> lineEditors = qFindChildren<QWidget *>(view.viewport(), QString::fromLatin1("TheEditor")); QCOMPARE(lineEditors.count(), 1); QPointer<QWidget> editor = lineEditors.at(0); QCOMPARE(editor->hasFocus(), true); QTest::keyClick(editor, Qt::Key(key)); QApplication::processEvents(); // The line edit has already been destroyed, so avoid that case. if (widget == TextEdit || widget == PlainTextEdit) { QVERIFY(!editor.isNull()); QCOMPARE(editor && editor->hasFocus(), expectedFocus); } }