Ejemplo n.º 1
0
void ItemOrderList::insertItem(const QString &label, bool checked, bool highlight, const QIcon &icon,
                               const ItemPtr &item, int targetRow)
{
    QListWidget *list = ui->listWidgetItems;
    QListWidgetItem *listItem = new QListWidgetItem(icon, label);
    const int row = targetRow >= 0 ? qMin(list->count(), targetRow) : list->count();
    list->insertItem(row, listItem);
    listItem->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
    setItemHighlight(listItem, highlight);

    m_items[listItem] = ItemWidgetPair(item);

    // Resize list to minimal size.
    const int w = list->sizeHintForColumn(0)
                + list->verticalScrollBar()->sizeHint().width() + 4;
    list->setMaximumWidth(w);

    if ( list->currentItem() == NULL )
        list->setCurrentRow(row);
}
Ejemplo n.º 2
0
void ItemOrderList::insertItem(const QString &label, bool checked, const QIcon &icon,
                               const ItemPtr &item, int targetRow)
{
    QListWidget *list = ui->listWidgetItems;
    auto listItem = new QListWidgetItem(icon, label);
    listItem->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
    m_items[listItem] = ItemWidgetPair(item, checked);

    const int row = targetRow >= 0 ? qMin(list->count(), targetRow) : list->count();
    list->insertItem(row, listItem);

    // Resize list to minimal size.
    if ( !isVisible() ) {
        const int w = list->sizeHintForColumn(0)
                    + list->verticalScrollBar()->sizeHint().width() + 4;
        list->resize( w, list->height() );
    }

    if ( list->currentItem() == nullptr )
        list->setCurrentRow(row);
}