Skip to content
QtWS25 Last Chance
  • 0 Votes
    3 Posts
    409 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
    2 Posts
    505 Views
    Christian EhrlicherC
    What's the benefit of FileSystemModel::getFileInfo()? I would guess your this pointer is a nullptr
  • 0 Votes
    6 Posts
    1k Views
    Christian EhrlicherC
    @arguskso said in Is it possible to notify items in the model without signals?: when new data is coming I can emmit signal with an id and all delegates will receive it and one with the corresponding id will send one more signal back to the model with it's index in the model. Delegates are used for displaying, they don't know anything about the internal data structure and don't have really access to anything else except it's own index. This can't work. You have to do it the way @JonB suggested to you.
  • 0 Votes
    8 Posts
    2k Views
    SGaistS
    You can check you model implementation with the QAbstractItemModelTester. See this wiki entry.
  • Subclassing QModelIndex - private constructor?

    Solved General and Desktop qmodelindex
    20
    0 Votes
    20 Posts
    3k Views
    D
    Hmmmmmmmm Ok. Time to rethink my live decisions :- ) Thanks so much for info & putting up with my whining. Thanks every one! :- ) Regards Dariusz
  • 0 Votes
    4 Posts
    2k Views
    Christian EhrlicherC
    @Dariusz said in Multithreading conversion of QModelIdnexList to treeItem crash: Well I have 100k items +/- to deal with Then you should avoid to dereference the pointers to not copy the data around. I created the base vectors via QVector<myTreeNode> vec(vecSize) and I access them all via [], so no thread should step over another thread, It does as your backtrace shows. Since you're using QVector which is implicit shared every write access to the container checks if the container needs to get detached. Maybe try with a non-implicit shared container instead (e.g. a std::vector) See http://doc.qt.io/qt-5/implicit-sharing.html for details.
  • 0 Votes
    10 Posts
    7k Views
    Y
    @VRonin Thank you. Yesterday, I tried same things. But it was not working than later on I found, I forget to add file name in SOURCE , HEADER. Now it is work as expectation.
  • 0 Votes
    4 Posts
    1k Views
    SGaistS
    Then you have to propagate the information when your underlying data changes.
  • Extract data from QModelIndex

    Solved General and Desktop qmodelindex qmodelindexlist
    3
    0 Votes
    3 Posts
    2k Views
    UnitScanU
    @mrjj yes, thank you!
  • 0 Votes
    21 Posts
    8k Views
    kshegunovK
    @Guy-Gizmo said: The whole point of me setting it up that way is that the actual logical structure of the data and the physical arrangement and implementation of it are conceptually completely separate. The latter is abstracted away by the interface of the former. Then I think the cleanest solution is to have a tree (or w/e) that represents your logical structure, and that will abstract the whole physical layer. For a simple example you can look at the docs - the simple tree model. You can put anything in that tree and it's basically your "data interface". It also shouldn't care that the physical nodes are destroyed as long as there's a logical node living. This way you don't have with model indexes and things getting destroyed in the background, because it's the middleman's responsibility. You should hover take care to notify the model when a node/leaf from the "logical structure" tree is destroyed (through the appropriate signals), so views can make proper adjustments. I hope that helps somewhat. Kind regards.
  • 0 Votes
    8 Posts
    3k Views
    TrilecT
    Thanks SGaist, will tag as solved.
  • 0 Votes
    9 Posts
    10k Views
    TrilecT
    Cool, Thanks for all the insite: I have solved the problem with a little more testing. For the sake of completeness and for others Ive included my code: void DialogStructureXML::on_btn_add_toroot_released() { QModelIndex currentIndex = ui->tree->selectionModel()->currentIndex(); QModelIndex rootIndex = ui->tree->rootIndex(); QModelIndex traceIndex = currentIndex; QModelIndex child = currentIndex; tree_model *model = (tree_model*) ui->tree->model(); int rowCount = model->rowCount(); int currentRow = 0; int prevRow = 0; //some string cleanup QString ItemText = ui->edit_textvaluefortree->text() ; ItemText.simplified(); //If its a valid index (ie: valid something in the GUI tree) trace back to the parent if ( traceIndex.isValid() ) { while ( traceIndex.isValid() ) { currentRow = traceIndex.row()+1; traceIndex = model->parent(traceIndex); } } if (!model->insertRow(currentRow, rootIndex)) return; child = model->index(currentRow, 0, rootIndex); //Column index 0 model->setData(child, QVariant( ItemText ), Qt::EditRole); return; }
  • 0 Votes
    3 Posts
    2k Views
    Q
    The dummy child is the culprit. It did not set the parent so the parent is invalid.
  • Reading a value from tableView

    Solved General and Desktop tableview qmodelindex index
    3
    0 Votes
    3 Posts
    3k Views
    G
    Thank you. It worked!
  • 0 Votes
    2 Posts
    2k Views
    SGaistS
    Hi and welcome to devnet, What about painting a partially transparent rectangle over the part of the text that should be highlighted ? You could draw the text first and then the rectangle over. Hope it helps
  • 0 Votes
    7 Posts
    8k Views
    mrjjM
    @StephanB hi and welcome The thread is 4 years old so the persons are most likely never to see it. The rest of the code belong to a custom/subclass model. So what call the code, it the framework / the view that use this model. You can read about it here: http://doc.qt.io/qt-5/model-view-programming.html https://www.youtube.com/watch?v=ytKDsJgJa4k http://www.informit.com/articles/article.aspx?p=1405547&seqNum=3