本文整理汇总了C++中QListWidget::addItem方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidget::addItem方法的具体用法?C++ QListWidget::addItem怎么用?C++ QListWidget::addItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidget
的用法示例。
在下文中一共展示了QListWidget::addItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;
QLabel* title = new QLabel("Custom widgets on a QListWidget");
title->setAlignment(Qt::AlignHCenter);
QListWidget* list = new QListWidget;
list->addItem("foo");
for (int i = 0; i < 5; i++){
QListWidgetItem* item;
item = new QListWidgetItem(list);
list->addItem(item);
// QPushButton* button = new QPushButton("hey");
Form *f = new Form;
item->setSizeHint(f->minimumSizeHint());
list->setItemWidget(item, f);
}
list->addItem("bar");
QVBoxLayout* layout = new QVBoxLayout(&window);
layout->addWidget(title);
layout->addWidget(list);
window.setLayout(layout);
window.show();
return a.exec();
}
示例2: testAddItems
void KListWidgetSearchLineTest::testAddItems()
{
QListWidget listWidget;
listWidget.addItem("Matching test item");
listWidget.addItem("Another test item");
KListWidgetSearchLine searchLine(0, &listWidget);
searchLine.setText("match");
// The initial filtering is delayed; we have to wait
while(!listWidget.item(1)->isHidden()) {
QTest::qWait(50);
}
QVERIFY(!listWidget.item(0)->isHidden());
QVERIFY(listWidget.item(1)->isHidden());
// Add two items
listWidget.addItem("Another item that matches the search pattern");
listWidget.addItem("This item should be hidden");
QVERIFY(!listWidget.item(0)->isHidden());
QVERIFY(listWidget.item(1)->isHidden());
QVERIFY(!listWidget.item(2)->isHidden());
QVERIFY(listWidget.item(3)->isHidden());
// Modify an item
listWidget.item(3)->setText("Now this item matches");
QVERIFY(!listWidget.item(0)->isHidden());
QVERIFY(listWidget.item(1)->isHidden());
QVERIFY(!listWidget.item(2)->isHidden());
QVERIFY(!listWidget.item(3)->isHidden());
}
示例3: setWindowTitle
MainWindow::MainWindow(QWidget *parent, QFlag flags) :
QMainWindow(parent, flags)
{
// Set window title
setWindowTitle("3D Computergrafik I - SS2015 - Aufgabenblatt 4");
// Create main container
QWidget *container = new QWidget();
setCentralWidget(container);
// Add list (on the left)
QListWidget *list = new QListWidget(container);
list->addItem("Aufgabe 12");
list->addItem("Aufgabe 13");
list->addItem("Aufgabe 14");
list->setMaximumWidth(150);
// Add stack of exercise windows (on the right)
QStackedWidget *stack = new QStackedWidget(container);
// Add exercises to widget
stack->addWidget(new GLViewer(new Exercise12()));
stack->addWidget(new GLViewer(new Exercise13()));
stack->addWidget(new GLViewer(new Exercise14()));
// Create layout
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(list);
layout->addWidget(stack);
container->setLayout(layout);
// Connect selection-event of list to select the current visible window
connect(list, SIGNAL(currentRowChanged(int)), stack, SLOT(setCurrentIndex(int)));
}
示例4: doEventPlace
void HistoryElementModifyEvent::doEventPlace()
{
if(!m_scene)
return;
LvlScene* lvlScene;
if(!(lvlScene = qobject_cast<LvlScene*>(m_scene)))
return;
LevelSMBX64Event rmEvents = m_event;
MainWinConnect::pMainWin->dock_LvlEvents->setEventToolsLocked(true);
QListWidgetItem * item;
item = new QListWidgetItem;
item->setText(rmEvents.name);
item->setFlags(Qt::ItemIsEditable);
item->setFlags(item->flags() | Qt::ItemIsEnabled);
item->setFlags(item->flags() | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable);
item->setData(Qt::UserRole, QString::number(rmEvents.meta.array_id) );
QListWidget* evList = MainWinConnect::pMainWin->dock_LvlEvents->getEventList();
LevelSMBX64Event NewEvent = rmEvents;
lvlScene->m_data->events.push_back(NewEvent);
evList->addItem(item);
lvlScene->m_data->meta.modified = true;
MainWinConnect::pMainWin->EventListsSync();
MainWinConnect::pMainWin->dock_LvlEvents->setEventToolsLocked(false);
}
示例5: fatalMessageReceived
void MessageHandlerWidget::fatalMessageReceived(const QString &app, const QString &message,
const QTime &time, const QStringList &backtrace)
{
if (Endpoint::isConnected() && !qobject_cast<MessageHandlerClient*>(ObjectBroker::object<MessageHandlerInterface*>())) {
// only show on remote side
return;
}
QDialog dlg;
dlg.setWindowTitle(tr("QFatal in %1 at %2").arg(app).arg(time.toString()));
QGridLayout *layout = new QGridLayout;
QLabel *iconLabel = new QLabel;
QIcon icon = dlg.style()->standardIcon(QStyle::SP_MessageBoxCritical, 0, &dlg);
int iconSize = dlg.style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, &dlg);
iconLabel->setPixmap(icon.pixmap(iconSize, iconSize));
iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
layout->addWidget(iconLabel, 0, 0);
QLabel *errorLabel = new QLabel;
errorLabel->setTextFormat(Qt::PlainText);
errorLabel->setWordWrap(true);
errorLabel->setText(message);
layout->addWidget(errorLabel, 0, 1);
QDialogButtonBox *buttons = new QDialogButtonBox;
if (!backtrace.isEmpty()) {
QListWidget *backtraceWidget = new QListWidget;
foreach (const QString &frame, backtrace) {
backtraceWidget->addItem(frame);
}
示例6: load
/** Loads the settings for this page */
void DirectoriesDialog::load()
{
/* get the shared directories */
rsiface->lockData(); /* Lock Interface */
std::list<std::string>::const_iterator it;
const std::list<std::string> &dirs = rsiface->getConfig().sharedDirList;
/* get a link to the table */
QListWidget *listWidget = ui.dirList;
/* remove old items ??? */
listWidget->clear();
for(it = dirs.begin(); it != dirs.end(); it++)
{
/* (0) Dir Name */
listWidget->addItem(QString::fromStdString(*it));
}
ui.incomingDir->setText(QString::fromStdString(rsiface->getConfig().incomingDir));
rsiface->unlockData(); /* UnLock Interface */
listWidget->update(); /* update display */
}
示例7: btnItemClicked
void CQReportDefinition::btnItemClicked()
{
assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
CModel* pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
if (!pModel) return;
std::vector< const CCopasiObject * > SelectedVector =
// CCopasiSelectionDialog::getObjectVector(this, CQSimpleSelectionTree::NO_RESTRICTION);
CCopasiSelectionDialog::getObjectVector(this, CQSimpleSelectionTree::AnyObject);
CQReportListItem * pItem;
if (SelectedVector.size() != 0)
{
QListWidget * pList = static_cast< QListWidget * >(mpReportSectionTab->currentPage());
std::vector< const CCopasiObject * >::const_iterator it = SelectedVector.begin();
std::vector< const CCopasiObject * >::const_iterator end = SelectedVector.end();
for (; it != end; ++it)
{
pItem = new CQReportListItem(*it);
pList->addItem(pItem);
}
mChanged = true;
}
return;
}
示例8: fillLists
void MainWindow::fillLists(DisplayData *display)
{
QListWidget* list;
unsigned char rowsCount = display->getRowCount();
if(font != nullptr)
for(int i=1;i<=4;i++)
{
switch(i)
{
case 1:list = listOfRows1;break;
case 2:list = listOfRows2;break;
case 3:list = listOfRows3;break;
case 4:list = listOfRows4;break;
}
if(rowsCount>=i)
{
list->clear();
for(int j=0;j<display->getCountOfLinesInRow(i-1);j++)
{
QString text = QString::number(j) + ")" + display->getLine(i-1,j)->getAsString(font);
list->addItem(text);
}
}
quint16 num = lcd->getCurrentLineNumber(i-1);
if(num<list->count()) list->setCurrentRow(num,QItemSelectionModel::SelectCurrent);
}
}
示例9: undo
void HistoryLog::undo()
{
int size = ui->HistoryLogList->count();
if(size > 0)
{
QString last = historyLog.back();
QListWidgetItem* it = ui->HistoryLogList->takeItem(size-1);
delete it;
QStringList pieces = last.split( ":" );
QString itemPiece = pieces[0].mid(0,pieces[0].count()-4).trimmed();
QString fromPiece = pieces[1].mid(0,pieces[1].count()-4).trimmed();
QString toPiece = pieces[2].trimmed();
QListWidget* from = findWidgetByName(fromPiece);
QListWidget* to = findWidgetByName(toPiece);
QListWidgetItem* item;
for(int idx = 0; idx< to->count(); idx++)
{
if(to->item(idx)->text() == itemPiece)
{
item = to->takeItem(idx);
from->addItem(item);
break;
}
}
historyLog.erase(historyLog.end()-1);
}
}
示例10: createPage
void ConfigPage::createPage()
{
QGroupBox* configGroup = new QGroupBox(tr("Provider Configuration"));
QListWidget* providerList = new QListWidget;
QDir dir("/usr/local/lib/Filu/provider");
int loop;
for (loop = 2; loop < (int) dir.count(); loop++)
{
QString provider = dir[loop];
//providerList->addItem(dir[loop]);
QListWidgetItem* providerItem = new QListWidgetItem(providerList);
if(isProviderInstalled(provider))
providerItem->setIcon(QIcon(":/icons/ok.xpm"));
else providerItem->setIcon(QIcon(":/icons/disable_gray.xpm"));
providerItem->setText(dir[loop]);
providerList->addItem(providerItem);
}
QPushButton* togleProviderBtn = new QPushButton;
togleProviderBtn->setText(tr("Activate"));
QHBoxLayout* serverLayout = new QHBoxLayout;
serverLayout->addWidget(providerList);
serverLayout->addWidget(togleProviderBtn);
QVBoxLayout* configLayout = new QVBoxLayout;
configLayout->addLayout(serverLayout);
configGroup->setLayout(configLayout);
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget(configGroup);
mainLayout->addStretch(1);
setLayout(mainLayout);
}
示例11: formChannelList
void MainWindow::formChannelList(){
if (m_availableChannelsQuery->getChannels().size() == 0 ) return;
else
{
m_availableChannels = m_availableChannelsQuery->getChannels();
}
m_subscribedChannels = m_subscribedChannelsQuery->getChannels();
QListWidget * listWidget = ui->channelsListWidget;
QListWidget * subscribedListWidget = ui->subscribedListWidget;
// Tab - channels
while(listWidget->count()>0)
{
listWidget->takeItem(0);
}
foreach (Channel s, m_availableChannels){
QListWidgetItem * item = new QListWidgetItem(s.getName());
if (isSubscribed(s.getName())){
item->setBackgroundColor(Qt::lightGray);
}
listWidget->addItem(item);
}
示例12: setEditorData
void CReportDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
const QAbstractItemModel* model = index.model();
QVariant data = index.data(Qt::DisplayRole);
//Populate the editor
if(data.type() != QVariant::List)
QStyledItemDelegate::setEditorData(editor,index);
QVariantList validReports = index.data(Qt::EditRole).toList();
QVariantList currentReportsList = data.toList();
QListWidget* listWidget = static_cast<QListWidget*>(editor);
// Prepare the items in the list
foreach(QVariant dataElement,validReports)
{
QString outString = dataElement.toString();
if(m_reportNameModel!=(QAbstractItemModel*)NULL)
{
outString+=":"+searchReportColumnForId(dataElement.toInt());
}
QListWidgetItem* item = new QListWidgetItem(outString);
item->setData(Qt::UserRole,dataElement);
//Now, determine if the ítem SHOULD be checked
if(currentReportsList.contains(dataElement))
{
item->setCheckState(Qt::Checked);
}
else
{
item->setCheckState(Qt::Unchecked);
}
listWidget->addItem(item);
}
示例13:
void
PreferencesDialog::moveSelectedListWidgetItems(QListWidget &from,
QListWidget &to) {
for (auto const &item : from.selectedItems()) {
auto actualItem = from.takeItem(from.row(item));
if (actualItem)
to.addItem(actualItem);
}
}
示例14: readVesselsToViews
void MainWindow::readVesselsToViews()
{
QString injectFromPath = findChild<QTextEdit*>("fileToInjectTextEdit")->toPlainText();
QString coreSavePath = findChild<QTextEdit*>("SavePathTextEdit")->toPlainText();
if(!isSFSFile(coreSavePath) || !isSFSFile(injectFromPath))
QMessageBox::warning(0, QString("File error"), QString("One or more of your paths have become invalid, please re-check them!"));
KSPS3::SaveFormater coreSave(coreSavePath);
std::vector<QSharedPointer<KSPS3::VesselData>> savedVessels;
importSave(&coreSave, &savedVessels);
QListWidget* savesList = findChild<QListWidget*>("vesselsInSaveListView");
for(std::size_t i = 0; i < savedVessels.size(); i++)
{
VesselListWidgetItem* element = new VesselListWidgetItem(savedVessels[i], savesList);
element->setText(savedVessels[i]->GetName());
m_diagnosticsWindow->append(*element->GetVesselData()->AccessFullText());
savesList->addItem(element);
}
KSPS3::SaveFormater injectionFile(injectFromPath);
std::vector<QSharedPointer<KSPS3::VesselData>> vesselsToInject;
importSave(&injectionFile, &vesselsToInject);
QListWidget* injectionList = findChild<QListWidget*>("InjectableVesselsListView");
for(std::size_t i = 0; i < vesselsToInject.size(); i++)
{
VesselListWidgetItem* element = new VesselListWidgetItem(vesselsToInject[i], injectionList);
element->setText(vesselsToInject[i]->GetName());
m_diagnosticsWindow->append(*element->GetVesselData()->AccessFullText());
savesList->addItem(element);
}
std::stringstream stringBuilder;
for(std::size_t i = 0; i < vesselsToInject.size(); i++)
{
stringBuilder << "vessel " << i << std::endl << vesselsToInject[i]->GetName().toStdString()
<< std::endl << "PID: " << vesselsToInject[i]->GetPID().toStdString();
}
findChild<QTextEdit*>("saveFileTextEdit")->setText(QString(stringBuilder.str().c_str()));
}
示例15: update_waveform_list
void FireTrackWidgetPrivate::update_waveform_list()
{
m_waveform_list->clear();
int N=m_waveforms.N3();
for (int i=0; i<N; i++) {
QListWidgetItem *it=new QListWidgetItem();
it->setText(QString("Neuron %1").arg(i+1));
it->setData(Qt::UserRole,i);
m_waveform_list->addItem(it);
}
}