本文整理汇总了C++中QTableWidgetItem::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ QTableWidgetItem::setData方法的具体用法?C++ QTableWidgetItem::setData怎么用?C++ QTableWidgetItem::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTableWidgetItem
的用法示例。
在下文中一共展示了QTableWidgetItem::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
void ConformerList::load()
{
QTableWidget* table(m_conformerListConfigurator.energyTable);
QList<Layer::Conformer*>
conformers(m_conformerList->findLayers<Layer::Conformer>(Layer::Children));
table->setRowCount(conformers.size());
QTableWidgetItem* energy;
int row(0);
QList<Layer::Conformer*>::iterator iter;
for (iter = conformers.begin(); iter != conformers.end(); ++iter) {
energy = new QTableWidgetItem( (*iter)->text() );
energy->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
energy->setData(Qt::UserRole, QVariantPointer<Layer::Conformer>::toQVariant(*iter));
table->setItem(row, 0, energy);
++row;
}
if (conformers.size() < 2) {
m_conformerListConfigurator.playButton->setEnabled(false);
m_conformerListConfigurator.forwardButton->setEnabled(false);
m_conformerListConfigurator.backButton->setEnabled(false);
m_conformerListConfigurator.bounceButton->setEnabled(false);
m_conformerListConfigurator.updateBondsButton->setEnabled(false);
m_conformerListConfigurator.speedSlider->setEnabled(false);
m_conformerListConfigurator.speedLabel->setEnabled(false);
}
}
示例2: createGUI
void Window::createGUI()
{
QList<QPair<QString, QColor> > list;
list << QPair<QString, QColor>(tr("Alice"), QColor("aliceblue")) <<
QPair<QString, QColor>(tr("Neptun"), QColor("aquamarine")) <<
QPair<QString, QColor>(tr("Ferdinand"), QColor("springgreen"));
QTableWidget *table = new QTableWidget(3, 2);
table->setHorizontalHeaderLabels(QStringList() << tr("Name")
<< tr("Hair Color"));
table->verticalHeader()->setVisible(false);
table->resize(150, 50);
for (int i = 0; i < 3; ++i) {
QPair<QString, QColor> pair = list.at(i);
QTableWidgetItem *nameItem = new QTableWidgetItem(pair.first);
QTableWidgetItem *colorItem = new QTableWidgetItem;
colorItem->setData(Qt::DisplayRole, pair.second);
table->setItem(i, 0, nameItem);
table->setItem(i, 1, colorItem);
}
table->resizeColumnToContents(0);
table->horizontalHeader()->setStretchLastSection(true);
QGridLayout *layout = new QGridLayout;
layout->addWidget(table, 0, 0);
setLayout(layout);
setWindowTitle(tr("Color Editor Factory"));
}
示例3: creatSearchedItems
void MusicLrcSearchTableWidget::creatSearchedItems(const QString &songname,
const QString &artistname, const QString &time)
{
int count;
setRowCount(count = m_downLoadManager->getSongIdIndex());
QTableWidgetItem *item = new QTableWidgetItem;
item->setData(MUSIC_CHECK_ROLE, false);
setItem(count - 1, 0, item);
item = new QTableWidgetItem;
item->setText(QFontMetrics(font()).elidedText(songname, Qt::ElideRight, 170));
item->setTextColor(QColor(50, 50, 50));
item->setTextAlignment(Qt::AlignCenter);
item->setToolTip(songname);
setItem(count - 1, 1, item);
item = new QTableWidgetItem;
item->setText(QFontMetrics(font()).elidedText(artistname, Qt::ElideRight, 144));
item->setTextColor(QColor(50, 50, 50));
item->setTextAlignment(Qt::AlignCenter);
item->setToolTip(artistname);
setItem(count - 1, 2, item);
item = new QTableWidgetItem(time);
item->setTextColor(QColor(50, 50, 50));
item->setTextAlignment(Qt::AlignCenter);
setItem(count - 1, 3, item);
item = new QTableWidgetItem;
item->setIcon(QIcon(QString::fromUtf8(":/radio/collect")));
setItem(count - 1, 4, item);
}
示例4: addPointToTable
void ccPointPairRegistrationDlg::addPointToTable(QTableWidget* tableWidget, int rowIndex, const CCVector3d& P, QString pointName)
{
assert(tableWidget);
if (!tableWidget)
return;
//add corresponding row in table
tableWidget->setRowCount(std::max<int>(rowIndex + 1, tableWidget->rowCount()));
tableWidget->setVerticalHeaderItem(rowIndex, new QTableWidgetItem(pointName));
//add point coordinates
for (int d = 0; d < 3; ++d)
{
QTableWidgetItem* item = new QTableWidgetItem();
item->setData(Qt::EditRole, QString::number(P.u[d], 'f', 6));
tableWidget->setItem(rowIndex, XYZ_COL_INDEX + d, item);
}
//add 'remove' button
{
if (rowIndex == 0)
tableWidget->setColumnWidth(DEL_BUTTON_COL_INDEX, 20);
//QTableWidgetItem* item = new QTableWidgetItem();
//tableWidget->setItem(rowIndex, DEL_BUTTON_COL_INDEX, item);
QToolButton* delButton = CreateDeleteButton();
connect(delButton, SIGNAL(clicked()), this, SLOT(onDelButtonPushed()));
tableWidget->setCellWidget(rowIndex, DEL_BUTTON_COL_INDEX, delButton);
}
}
示例5: foreach
foreach (const QString &genre, genres) {
QTableWidgetItem *item = new QTableWidgetItem(genre);
item->setData(Qt::UserRole, genre);
int row = ui->genres->rowCount();
ui->genres->insertRow(row);
ui->genres->setItem(row, 0, item);
}
示例6: while
void
SeqLenAnalysis::redraw()
{
while (ui->seqLenTable->rowCount() > 0) {
ui->seqLenTable->removeRow(0);
}
for (auto& data: m_data[m_currentK]) {
ui->seqLenTable->insertRow(0);
auto add = [&](int x, QVariant value) {
QTableWidgetItem* w = new QTableWidgetItem;
w->setData(Qt::DisplayRole, value);
ui->seqLenTable->setItem(0, x, w);
m_widgetData[w] = &data;
};
add(0, data.bit);
add(1, data.n);
add(2, data.mean);
add(3, data.stddev);
add(4, data.min);
add(5, data.max);
}
}
示例7: tableChanged
void IndexDialog::tableChanged(const QString &tb)
{
tbname = tb;
tbColumnList->clearContents();
QSqlDatabase db = QSqlDatabase::database(conname);
QSqlRecord record = db.record(tbname);
int count = record.count();
tbColumnList->setRowCount(count);
for(int i=0;i<count;i++){
QTableWidgetItem *item = new QTableWidgetItem;
item->setData(Qt::EditRole,false);
item->setFlags(Qt::ItemIsEnabled);
tbColumnList->setItem(i,0,item);
item = new QTableWidgetItem;
item->setText(record.fieldName(i));
tbColumnList->setItem(i,1,item);
item = new QTableWidgetItem;
item->setText(QString());
tbColumnList->setItem(i,2,item);
item = new QTableWidgetItem;
item->setText(QString());
tbColumnList->setItem(i,3,item);
}
}
示例8: boldfont
// get speaker's themes by language
QTableWidget *PublicTalks::getSpeakerPublicTalks(int kieli_id, int personid, QString select) {
QTableWidget *table = new QTableWidget(0,3);
table->verticalHeader()->setVisible(false);
//sitten vectoriin kaikki aiheet
std::vector<sql_item> q;
// q = sql.selectSql("SELECT * FROM Esitelmat, P_esitelmat WHERE Esitelmat.kieli_id = '"+ kielet[0].getValue("id") +"'"
// " AND Esitelmat.aihe_id = P_esitelmat.aihe_id"
// " AND P_esitelmat.puhuja_id = '" + QString::number(personid) + "'");
q = sql.selectSql("SELECT Esitelmat.*, P_esitelmat.puhuja_id, yleisokokous.pvm FROM Esitelmat "
"LEFT JOIN yleisokokous ON Esitelmat.aihe_id = yleisokokous.aihe_id "
"LEFT JOIN P_esitelmat ON Esitelmat.aihe_id = P_esitelmat.aihe_id "
"WHERE P_esitelmat.puhuja_id = '" + QString::number(personid) + "' "
"AND Esitelmat.kieli_id = '"+ langId +"' "
"GROUP BY Esitelmat.aihe_id ORDER BY Esitelmat.aihe_id");
table->setRowCount(q.size()+1);
for(unsigned int i = 0; i < q.size(); i++) {
int value = QVariant(q[i].getValue("aihe_id")).toInt();
QTableWidgetItem *item = new QTableWidgetItem();
item->setData(Qt::DisplayRole,value);
table->setItem(i+1,0,item);
//table->setItem(i+1,0,new QTableWidgetItem(q[i].getValue("aihe_id")));
table->setItem(i+1,1,new QTableWidgetItem(q[i].getValue("aihe")));
if(table->item(i+1,1)->text() == select) {
QFont boldfont(table->item(i+1,1)->font().family(),
table->item(i+1,1)->font().pointSize(),
QFont::Bold);
table->item(i+1,1)->setFont(boldfont);
}
table->setItem(i+1,2,new QTableWidgetItem(q[i].getValue("pvm")));
}
return table;
}
示例9: createAllItems
void MusicConnectTransferWidget::createAllItems(const MusicSongs &songs)
{
ui->playListTableWidget->clear();
if(ui->allSelectedcheckBox->isChecked())
{
ui->allSelectedcheckBox->click();
}
ui->playListTableWidget->setRowCount(songs.count());
for(int i=0; i<songs.count(); ++i)
{
MusicSong song = songs[i];
QTableWidgetItem *item = new QTableWidgetItem;
item->setData(MUSIC_CHECK_ROLE, false);
ui->playListTableWidget->setItem(i, 0, item);
item = new QTableWidgetItem;
item->setText(QFontMetrics(font()).elidedText(song.getMusicName(), Qt::ElideRight, 280));
item->setToolTip(song.getMusicPath());
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
ui->playListTableWidget->setItem(i, 1, item);
item = new QTableWidgetItem;
item->setText(QFontMetrics(font()).elidedText(song.getMusicTime(), Qt::ElideRight, 40));
item->setToolTip(song.getMusicTime());
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
ui->playListTableWidget->setItem(i, 2, item);
}
}
示例10: tagColorChanged
void
TagColorEditor::cellDoubleClicked(int row, int col)
{
if (row == 0 && col > 0)
return;
QTableWidgetItem *item = table->item(row, col);
uchar *colors = Global::tagColors();
//int index = row*8 + col;
int index = 0;
if (row > 0) index = 1 + (row-1)*5 + col;
QColor clr = QColor(colors[4*index+0],
colors[4*index+1],
colors[4*index+2]);
clr = DColorDialog::getColor(clr);
if (!clr.isValid())
return;
colors[4*index+0] = clr.red();
colors[4*index+1] = clr.green();
colors[4*index+2] = clr.blue();
item->setData(Qt::DisplayRole, QString("%1").arg(index));
item->setBackground(clr);
emit tagColorChanged();
}
示例11: AddItem
void ChangesDialog::AddItem(const AppCore::Entry& Data)
{
const int Rows = ui->Items->rowCount();
const bool Sorting = ui->Items->isSortingEnabled();
const bool Block = ui->Items->blockSignals(true);
ui->Items->setSortingEnabled(false);
ui->Items->insertRow(Rows);
QTableWidgetItem* IndexBox = new QTableWidgetItem();
QTableWidgetItem* CheckBox = new QTableWidgetItem();
IndexBox->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
IndexBox->setData(Qt::UserRole, Data.ID);
IndexBox->setData(Qt::EditRole, Data.ID);
IndexBox->setCheckState(Data.isEnabled ? Qt::Checked : Qt::Unchecked);
CheckBox->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
CheckBox->setCheckState(Data.isRegExp ? Qt::Checked : Qt::Unchecked);
CheckBox->setText(Data.isRegExp ? tr("Yes") : tr("No"));
ui->Items->setItem(Rows, 0, IndexBox);
ui->Items->setItem(Rows, 1, new QTableWidgetItem(Data.Source));
ui->Items->setItem(Rows, 2, new QTableWidgetItem(Data.Replace));
ui->Items->setItem(Rows, 3, CheckBox);
ui->Items->blockSignals(Block);
ui->Items->setSortingEnabled(Sorting);
if (Data.ID == -1) ui->Items->scrollToItem(IndexBox);
}
示例12: setupDevice
void ViennaMiniForm::setupDevice(std::vector<int> const& segment_indices)
{
if(resize_device_parameters)
{
device_parameters.clear();
}
ui->tableWidget->clearContents();
ui->tableWidget->setRowCount(segment_indices.size());
for(int i = 0; i < segment_indices.size(); i++)
{
QTableWidgetItem *item = new QTableWidgetItem(QString::number(segment_indices[i]));
item->setFlags(item->flags() ^ Qt::ItemIsEditable); // make the table not editable
item->setData(Qt::UserRole, segment_indices[i]);
ui->tableWidget->setItem(i, 0, item);
}
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
//ui->tableWidget->verticalHeader()->setStretchLastSection(true);
// now, activate the device tab!
ui->tabWidget->setTabEnabled(1, true);
// select the first segment by default
ui->tableWidget->setCurrentCell(segment_indices[0], 0);
// this->toggleParameters(true);
// this->showSegmentParameters(0,0); //show default parameters for the initial selection
}
示例13: initTable
void ShortcutsImpl::initTable(MainImpl *main)
{
QList<QObject*> childrens = main->children();
QListIterator<QObject*> iterator(childrens);
int row = 0;
while( iterator.hasNext() )
{
QObject *object = iterator.next();
QAction *action = qobject_cast<QAction*>(object);
if (action)
{
QString text = action->text().remove("&");
if ( !text.isEmpty() && !(action->data().toString().contains("Recent|")) )
{
QString shortcut = action->shortcut();
QTableWidgetItem *newItem = new QTableWidgetItem(text);
newItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
newItem->setData(Qt::UserRole, addressToVariant(object));
newItem->setIcon(action->icon());
table->setRowCount(row+1);
table->setItem(row, 0, newItem);
table->setItem(row++, 1, new QTableWidgetItem(shortcut));
}
}
table->sortItems( 0 );
}
QHeaderView *header = table->horizontalHeader();
header->resizeSection( 0, 230 );
table->verticalHeader()->hide();
}
示例14: on_addEventButton_clicked
void MainWindow::on_addEventButton_clicked()
{
// QTreeWidgetItem* parentWidget = selectedTreeWidgetItem();
Task* parentTask = selectedTask();
if (parentTask == NULL) return;
Event* newEvent = addEvent(parentTask, "");
ui->tableEvents->blockSignals(true);
ui->tableEvents->insertRow(0);
QTableWidgetItem *widgetUid = new QTableWidgetItem();
widgetUid->setText(newEvent->mUID);
widgetUid->setData(Qt::UserRole, qVariantFromValue((void*) newEvent));
ui->tableEvents->setItem(0, 0, widgetUid);
QTableWidgetItem *widgetName = new QTableWidgetItem();
widgetName->setText(newEvent->mName);
ui->tableEvents->setItem(0, 1, widgetName);
DateItem *widgetStart = new DateItem();
widgetStart->setText(newEvent->mStartTime.toString());
widgetStart->mTime = newEvent->mStartTime;
ui->tableEvents->setItem(0, 2, widgetStart);
DateItem *widgetEnd = new DateItem();
widgetEnd->setText(newEvent->mEndTime.toString());
widgetEnd->mTime = newEvent->mEndTime;
ui->tableEvents->setItem(0, 3, widgetEnd);
ui->tableEvents->blockSignals(false);
}
示例15: displayComp
void AddLink::displayComp(vector<Computer>& computer)
{
ui->table_linking->setSortingEnabled(false);
ui->table_linking->clearContents();
ui->table_linking->setColumnCount(5);
ui->table_linking->setRowCount(computer.size());
ui->table_linking->setHorizontalHeaderItem(0,new QTableWidgetItem(QString("id")));
ui->table_linking->setHorizontalHeaderItem(1,new QTableWidgetItem(QString("Name")));
ui->table_linking->setHorizontalHeaderItem(2,new QTableWidgetItem(QString("Year")));
ui->table_linking->setHorizontalHeaderItem(3,new QTableWidgetItem(QString("Type")));
ui->table_linking->setHorizontalHeaderItem(4,new QTableWidgetItem(QString("Built")));
for(size_t i = 0; i < computer.size(); i++)
{
Computer temp = computer[i];
QTableWidgetItem* id = new QTableWidgetItem;
id->setData(Qt::DisplayRole,temp.getID());
ui->table_linking->setItem(i,0, id);
ui->table_linking->setItem(i,1, new QTableWidgetItem(QString::fromStdString(temp.getName())));
ui->table_linking->setItem(i,2, new QTableWidgetItem(QString::number(temp.getYear())));
ui->table_linking->setItem(i,3, new QTableWidgetItem(QString::fromStdString(temp.getType())));
ui->table_linking->setItem(i,4, new QTableWidgetItem(QString::number(temp.getBuilt())));
}
ui->table_linking->setSortingEnabled(true);
}