void OperationsDelegate::setEditorData(QWidget *editor,
                                       const QModelIndex &index) const
      {
      const QVariant value = index.data(Qt::EditRole);
      if (value.type() == QVariant::StringList) {
            QListWidget *lw = qobject_cast<QListWidget *>(editor);
            const auto items = lw->findItems(index.data(Qt::DisplayRole).toString(), Qt::MatchExactly);
            if (!items.empty())
                  lw->setCurrentItem(items.first());
            else
                  lw->setCurrentItem(lw->item(0));

            const int extraWidth = 25;
            const int extraHeight = 6;
            lw->setMinimumWidth(lw->sizeHintForColumn(0) + extraWidth);
                        // to prevent possible hiding bottom part of the list
            const int h = lw->count() * (lw->visualItemRect(lw->currentItem()).height() + extraHeight);
            const int y = (lw->parentWidget() && (lw->parentWidget()->rect().bottom() < lw->y() + h))
                        ? lw->parentWidget()->rect().bottom() - h - extraHeight : lw->y();
            lw->setGeometry(lw->x(), y, lw->width(), h);
                        // now lw can be partially hidden behind the tree view
                        // if tree view has small rect, so set parent of lw
                        // to app window and map coordinates accordingly to leave lw in place
            const auto globalCoord = lw->parentWidget()->mapToGlobal(lw->geometry().topLeft());
            lw->setParent(appWindow);
            const auto newLocalCoord = appWindow->mapFromGlobal(globalCoord);
            lw->setGeometry(newLocalCoord.x(), newLocalCoord.y(), lw->width(), h);
            }
      else        // single value
            QStyledItemDelegate::setEditorData(editor, index);
      }
void MainWindow::resizeEvent(QResizeEvent *)
{
    QListWidget *lst = ui->lst_debug;
    QRect geo = lst->geometry();
    geo.setHeight( this->height() - geo.top() - 20 );
    lst->setGeometry(geo);
}
Beispiel #3
0
void CMainWnd::createView(XMLConfig *pXMLConfig, const DOMNode *pNode) {

	QWidget *pTab; QListWidget *pListWidget = 0;
	pTab = new QWidget(m_pTabContainer);
	pListWidget = new QListWidget(pTab);
	pListWidget->setGeometry(QRect(5, 5, pXMLConfig->gattr("view:width").toUInt() - 32, pXMLConfig->gattr("view:height").toUInt() - 56));
	pListWidget->setSelectionMode(QAbstractItemView::NoSelection);
	pListWidget->setFont(QFont("courier new", 9));
	m_pTabContainer->insertTab(0, pTab, pXMLConfig->attr(pNode, "caption"));
	QString sTmp = pXMLConfig->attr(pNode, "id");
	m_mViews[sTmp.right(sTmp.length() - 1).toUShort()] = pListWidget;
}