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


C++ QListWidget::addItem方法代码示例

本文整理汇总了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();
}
开发者ID:manashmndl,项目名称:QtCppSolutions,代码行数:32,代码来源:main.cpp

示例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());
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:34,代码来源:klistwidgetsearchlinetest.cpp

示例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)));
}
开发者ID:Tymolc,项目名称:CG-I-2015,代码行数:34,代码来源:mainwindow.cpp

示例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);
}
开发者ID:Wohlhabend-Networks,项目名称:PGE-Project,代码行数:31,代码来源:historyelementmodifyevent.cpp

示例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);
    }
开发者ID:ChristopherHahn,项目名称:GammaRay,代码行数:32,代码来源:messagehandlerwidget.cpp

示例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 */


}
开发者ID:autoscatto,项目名称:retroshare,代码行数:30,代码来源:DirectoriesDialog.cpp

示例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;
}
开发者ID:sachiinb,项目名称:COPASI,代码行数:30,代码来源:CQReportDefinition.cpp

示例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);
    }
}
开发者ID:hermixy,项目名称:QtModbusLcd,代码行数:28,代码来源:mainwindow.cpp

示例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);
	}
}
开发者ID:FrankZZ,项目名称:AvanScrum,代码行数:27,代码来源:HistoryLog.cpp

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

示例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);
    }
开发者ID:4ukuta,项目名称:core,代码行数:27,代码来源:mainwindow.cpp

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

示例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);
  }
}
开发者ID:b2kguga,项目名称:mkvtoolnix,代码行数:9,代码来源:preferences_dialog.cpp

示例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()));
}
开发者ID:DaymareDev,项目名称:KSPS3,代码行数:42,代码来源:mainwindow.cpp

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


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