Skip to content
  • QTreeView empty

    Solved General and Desktop qtreeview qabstractitemmo
    6
    0 Votes
    6 Posts
    83 Views
    M
    @Christian-Ehrlicher yep that was it. Can't believe I missed that for so long thank you both for the help
  • 0 Votes
    3 Posts
    153 Views
    Christian EhrlicherC
    ... or check inside the delegate functions if the row is still the one e.g. by checking the data to display.
  • 0 Votes
    3 Posts
    395 Views
    J
    Ah yes, of course, thats makes a lot of sense. I'll set the item as selected, and change the way i draw a selected item to match that of a hovered item. Thank you i think i was trying to overcomplicate things.
  • 0 Votes
    8 Posts
    855 Views
    S
    @JonB @SGaist @DerReisende Thank you all very much. Thats kinda tedious to do but guess thats how it is. Appreciate all your help and indeed mapFrom and mapToSource are what fixes my issue. :D Y'all have a nice day.
  • 0 Votes
    8 Posts
    756 Views
    SGaistS
    @Jammin44fm the paint method of QGraphicsItem is public so you can call it yourself with the painter you use in the delegate.
  • 0 Votes
    26 Posts
    5k Views
    SGaistS
    @StudentScripter great ! Then please mark the model as solved using the "Topic Tools" button or the dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)
  • 0 Votes
    3 Posts
    371 Views
    S
    @Pl45m4 Worked like a charm, thank you very much. :)
  • 0 Votes
    1 Posts
    230 Views
    No one has replied
  • 0 Votes
    19 Posts
    2k Views
    S
    @Chris-Kawa thank you very much. That definitely helped a lot. :) I have done the manual positioning now, so all delegates line up with the actual widget. :) void ViewLayerItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; initStyleOption(&opt, index); // Überprüfen Sie, ob der aktuelle Index bearbeitet wird if (index == currentlyEditedIndex) { return; } // Setzen Sie die Werte der SpinBox und CheckBox basierend auf den Modellwerten QString lineEditvalue = index.model()->data(index, Qt::EditRole).toString(); bool checkBoxValue = index.model()->data(index, Qt::CheckStateRole).toBool(); // Laden Sie das Icon und skalieren Sie es QPixmap iconPixmap("://resource/quick.png"); // Ersetzen Sie dies durch den Pfad zu Ihrer Icon-Datei QPixmap scaledPixmap = iconPixmap.scaled(32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation); // Berechnen Sie die Position für das Icon int centerY = option.rect.top() + option.rect.height() / 2; int iconY = centerY - scaledPixmap.height() / 2; QPoint iconPos = QPoint(option.rect.left() + 10, iconY); // Zeichnen Sie das Pixmap mit dem QPainter painter->drawPixmap(iconPos, scaledPixmap); // Berechnen Sie die Position und Größe für das LineEdit QRect lineEditRect = option.rect; lineEditRect.setLeft(iconPos.x() + scaledPixmap.width() + 10); // Adjust as needed lineEditRect.setRight(option.rect.right() - 10); // Adjust as needed // Erstellen Sie ein QStyleOptionFrame für das LineEdit QStyleOptionFrame lineEditOption; lineEditOption.lineWidth = 1; // Setzen Sie die Liniendicke auf 1 lineEditOption.rect = lineEditRect; // Zeichnen Sie das LineEdit QApplication::style()->drawControl(QStyle::CE_ShapedFrame, &lineEditOption, painter); // Zeichnen Sie den Text des LineEdits painter->drawText(lineEditOption.rect.adjusted(2,0,0,0), Qt::AlignLeft | Qt::AlignVCenter, lineEditvalue); // Berechnen Sie die Position und Größe für die CheckBox QRect checkBoxRect = option.rect; checkBoxRect.setLeft(lineEditRect.right() - 22); // Adjust as needed checkBoxRect.setRight(option.rect.right() - 10); // Adjust as needed // Erstellen Sie ein QStyleOptionButton für die CheckBox QStyleOptionButton checkBoxOption; checkBoxOption.state = checkBoxValue ? QStyle::State_On : QStyle::State_Off; checkBoxOption.rect = checkBoxRect; // Zeichnen Sie die CheckBox QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkBoxOption, painter); }
  • 0 Votes
    5 Posts
    587 Views
    SGaistS
    @StudentScripter For the grouping you have to use an adequate data structure. As for hovering, IIRC, you have to have mouse tracking enabled on the view.
  • 0 Votes
    3 Posts
    416 Views
    Y
    Remove space; Inside the table cell but outside my custom widget Here some code snap. @ChrisW67 #include "ElementsListWidget.h" #include "AbstractElement.h" #include "ElementDragEventHandler.h" #include <QAbstractScrollArea> #include <QGridLayout> #include <QLabel> #include <QPixmap> #include <QScrollArea> #include <QSortFilterProxyModel> #include <QVariant> #include <qscrollbar.h> #include <qstandarditemmodel.h> #include <qtreeview.h> ElementsListWidget::ElementsListWidget(QWidget* parent) : QWidget(parent) { QVBoxLayout* mainlayout = new QVBoxLayout(this); mainlayout->setContentsMargins(0, 0, 0, 0); elementsListLayout = new QTreeView(this); elementsListLayout->setContentsMargins(0, 0, 0, 0); elementsListLayout->setHeaderHidden(true); elementsListLayout->setIndentation(0); elementsListLayout->setUniformRowHeights(false); elementsListLayout->setObjectName("ElementsListWidget"); elementsListLayout->setSelectionMode(QAbstractItemView::NoSelection); elementsListLayout->verticalScrollBar()->parent()->setProperty("background_transparent", true); elementsListLayout->horizontalScrollBar()->parent()->setProperty("background_transparent", true); sourceModel = new QStandardItemModel(this); elementsListLayout->setModel(sourceModel); mainlayout->addWidget(elementsListLayout); setLayout(mainlayout); elementsPerRow = 3; totalModelElements = 0; sourceModel->setColumnCount(elementsPerRow); } void ElementsListWidget::addElement(AbstractElement* element) { elementsModel << element; showWidgetOnView(createDisplayUnit(element)); } QWidget* ElementsListWidget::createDisplayUnit(AbstractElement* element) { if (!element) { return nullptr; } QWidget* elementDispalyWidget = new QWidget; elementDispalyWidget->setObjectName("elementDisplayUnit"); QVBoxLayout* elementdisplayLay = new QVBoxLayout(elementDispalyWidget); //elementdisplayLay->setContentsMargins(0, 0, 0, 0); QLabel* elementIconLabel = new QLabel(elementDispalyWidget); elementIconLabel->setObjectName("elementIconLabel"); elementIconLabel->setProperty("element", QVariant::fromValue(static_cast<AbstractElement*>(element))); elementIconLabel->setCursor(Qt::OpenHandCursor); elementIconLabel->setAlignment(Qt::AlignCenter); elementIconLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); elementIconLabel->installEventFilter(new ElementDragEventHandler(elementIconLabel)); // Install event filter elementIconLabel->setPixmap(element->getImage().scaled(50, 50)); QLabel* elementNameLabel = new QLabel(element->getName(), elementDispalyWidget); elementNameLabel->setObjectName("elementNameLabel"); elementNameLabel->setAlignment(Qt::AlignCenter); elementNameLabel->setWordWrap(true); elementdisplayLay->setAlignment(Qt::AlignHCenter); elementdisplayLay->addWidget(elementIconLabel); elementdisplayLay->addWidget(elementNameLabel); elementdisplayLay->addStretch(); elementDispalyWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); return elementDispalyWidget; } void ElementsListWidget::setElementsPerRow(int numberOfelementsPerRow) { if (numberOfelementsPerRow > 0) { elementsPerRow = numberOfelementsPerRow; } } void ElementsListWidget::serachElement(const QString& searchText) { clearModel(); // Iterate through the stored widgets in elementWidgetModel for (AbstractElement* element : elementsModel) { if (element && element->getName().contains(searchText, Qt::CaseInsensitive)) { showWidgetOnView(createDisplayUnit(element)); } } } void ElementsListWidget::showWidgetOnView(QWidget* elementDisplayUnit) { if (elementDisplayUnit == nullptr) { return; } QStandardItem* item = new QStandardItem; // Calculate the row and column count for the new element int row = totalModelElements / elementsPerRow; int column = totalModelElements % elementsPerRow; sourceModel->setItem(row, column, item); elementsListLayout->setIndexWidget(item->index(), elementDisplayUnit); totalModelElements++; } void ElementsListWidget::clearModel() { sourceModel->clear(); totalModelElements = 0; } styel sheet for few widget QWidget#ElementsListWidget { background-color: #DAE0E9; color: #3B5571; border: none; } #elementDisplayUnit { background-color: transparent; font-size: 14px; } #elementIconLabel { width: 64px; background-color: #ffffff; border: 1px solid #BEC9CD; height: 64px; position: relative; /* align-items: center; */ border-radius: 5px; /* justify-content: center; */ background-color: #FFFFFF; } #elementIconLabel:hover { background-color: lightgray; } #elementNameLabel { padding: 0px 0 0 0; font-size: 11px; max-width: 64px; text-align: center; line-height: 12px; /* text-overflow: ellipsis; */ background-color: transparent; /* word-wrap: break-word; */ font-weight: bold; }
  • 0 Votes
    1 Posts
    362 Views
    No one has replied
  • QTreeView: hide box in the corner

    Solved General and Desktop qtreeview qtdesigner
    5
    0 Votes
    5 Posts
    495 Views
    Fire CubeF
    Many Thanks That worked great.
  • 0 Votes
    7 Posts
    1k Views
    BeaverShallBurnB
    @JonB Huge thanks, you solved the puzzle for me!
  • 0 Votes
    3 Posts
    2k Views
    Joel BodenmannJ
    @Gojir4 That worked well. I'm not sure how I could have missed this simple solution... Thank you a lot!
  • QTreeView::VisualRect return invalid

    Solved General and Desktop qtreeview
    3
    0 Votes
    3 Posts
    441 Views
    JonBJ
    @Dariusz Interesting :) I guess it generates it only on demand, and doesn't do so during model reset.
  • Styling all of QtreeView...

    Unsolved General and Desktop qstyle qproxystyle qstylesheet qtreeview qwidget
    3
    0 Votes
    3 Posts
    840 Views
    D
    @VRonin I want to do some heavy changes/customisations... stuff I cant do in CSS... Like moving expand button to opposite of tree, changing location of checkbox, changing indentation of child items. How can I control indentation of child items? I need it now :/ I keep getting "invisible" hitboxes as my child item is moved to left visually but hitboxes are drawn in original places :/// Ideas? I just realized there is "setIndentation"... sigh............ Ok that kinda works, how can I set indentation per row? :D
  • 0 Votes
    2 Posts
    413 Views
    F
    A colleague of mine, that used Qt for years, helped me. The culprit was (other than me) that I wrongly created the parent of the children.
  • Word wrap and links in QTreeView

    Moved Unsolved Qt for Python qtreeview delegate wordwrap hyperlink
    1
    0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    5 Posts
    862 Views
    SGaistS
    I may have misread the code back then but nice that you are taking care of it.