Skip to content
  • 0 Votes
    3 Posts
    117 Views
    S

    @SGaist Thank you very much. Gonna have a read trough it. :D

  • 0 Votes
    3 Posts
    260 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
    244 Views
    JonBJ

    @johnco3
    I'm afraid I know nothing about std::variant, but a couple of observations.

    Your setData() is void. QStandardItemModel's is bool. Have you checked the return result when you call that, you never know if it might be barfing?

    Your setData() defaults to Qt::UserRole + 1. How does your item->data().value<PortVariant>() pass that role to fetch?

    setData() copies its argument. I assume the equivalent code to test would be something like:

    PortVariant portVariant = port; QVariant v = QVariant::fromStdVariant(portVariant); QVariant v2 = v1; const auto& portVariant = v2.value<PortVariant>();

    How does that come out? You might also call QVariant::canConvert<>() to check, including on your item->data().

    I assume all the various component types in your structs are serializable to QVariant without further registration.

  • 0 Votes
    13 Posts
    1k Views
    D

    @JonB I'm in python, I cant just do stream >> QVector<QStandardItemData> I'm afraid :/
    I'd have to deserialize each data object by hand to find correct offset byte to next role in vector I think

    Update!
    Welp turns out there is readQVariant!

    i = QStandardItem("hello") i.setData("dasdas", 15241) i.setData(5325, 15242) i.setData(["vdsvds"], 15243) i.setData(["vdsvds"], 15245) ar = QByteArray() s = QDataStream(ar, QIODevice.ReadWrite) i.write(s) r = QDataStream(ar, QIODevice.ReadOnly) val = 0 v = r.readUInt32() for a in range(v): role = r.readInt32() var = r.readQVariant() print(role, var) print(v)

    This works, wop wop!

  • 0 Votes
    2 Posts
    191 Views
    SGaistS

    Hi,

    I would venture to say no :-)

    Which version of Qt are you using ?
    In which OS ?
    Are doing the move at the same level ?
    Do you have a filter ?

  • 0 Votes
    7 Posts
    704 Views
    BeaverShallBurnB

    @JonB

    Huge thanks, you solved the puzzle for me!

  • 0 Votes
    3 Posts
    480 Views
    S

    @VRonin Thanks.
    It worked.
    We have used delegates because we have combobox, lineedit also.
    So we have put check for combobox, not to update via delegate.

  • 0 Votes
    4 Posts
    563 Views
    Christian EhrlicherC

    @Joel-Bodenmann said in QStandardItem custom drag MIME:

    However, I'd like to understand why QStandardItem does not offer a setMimeData() function.

    Because noone wants to create a mime data just on suspicion for every item.

  • 0 Votes
    2 Posts
    2k Views
    Chris KawaC

    which style parameter do I have to edit to control the color of item when the widget loses focus?

    QTreeView::item:active { color: red; } /* When widget has focus*/ QTreeView::item:!active { color: blue; } /* When widget doesn't have focus*/

    if I do show-decoration-selected: 1; How do I control decoration color ?

    It depends on the platform styling. For example on Windows it only colors on hover the little arrow that expands/collapses the branch and that arrow is painted by a system style call so you can't control its color. You can however replace the system styling and change the branch images to your own with any color you like. See Customizing QTreeView for examples.

  • 0 Votes
    9 Posts
    5k Views
    S

    @JonB
    I added comments in my code. I think I should explain it clearly. Sorry... but please help.

  • 0 Votes
    3 Posts
    4k Views
    S

    @SGaist said in Add Qlabel as item in QTableview:

    QStyledItemDelegate

    Ok..I'll try with that.
    from google search maybe this kind of output it will give, which maybe as our requirement.
    0_1558578799369_da2ccc76-385d-40ee-954a-79cbbe227dc3-image.png

    Else, I have some lengthy approach..implement custom label with mousepressevent handled which emits the object name and add these custom labels, 20 in HLayout and add hlayouts in a vlayout...

    Thanks!

  • 0 Votes
    15 Posts
    4k Views
    JonBJ

    @n-2204
    Please try to format your posts readably. For lines of code use the Code tag when posting, or but lines of 3-backticks above & below.

    You are also now asking this same question in a new thread you have created (https://forum.qt.io/topic/125774/qtableview-how-to-make-noneditable-column). You should stick to one thread, not create multiple ones.

    where i should give like it will be applicable for table1 or table2

    I don't know what you mean. To use the flags() approach you must sub-class QStandardItemModel, which I assume is what your GAS_tool is, else this will have no effect.

    If you want to use the setFlags() approach, you do not need to sub-class, but must set the flags explicitly on each item which is to be non-editable.

    I also wrote this in your other thread.

  • 0 Votes
    4 Posts
    755 Views
    D

    @dheerendra thanks! I had a feeling that was the case, but QSortFilterProxyModel is a very interesting discovery! I used it a few times but humh... I will look into that more! Thanks! If you have any suggestions/tutorials/read please shoot away, bit lost atm as to what to look for there.

    @Eeli-K Yep, I subclass QAbstractItemModel & created my own treeItem from the ground up so I have full control over these 2 entities. I Extended QtreeView with some "helper" handlers of my data/model but that's it. Did not touch QModelIndex to me its black magic ;- ) Will think about solving that internally somehow. If I were to redirect the read of some widgets, what would I need to extend more? index/data/row functions? Hmm I need to think about it more. Getting some lightbulbs slowly here but I wonder if it's backward. Atm, I'm thinking that each of the virtual functions I had to overload would have to return native model data 1st and once that's done, return the instanced model/items data... uhhh getting complicated humhhhh humhhh humhhhh interesting. Thanks!

    Regards
    Dariusz
    TIA

  • 0 Votes
    27 Posts
    6k Views
    JKSHJ

    @elfring said in Returning C++ references from more programming interfaces?:

    For example, why should Qt provide extensions that break encapsulation and increase the risk of errors?

    I suggest to use algorithms which can work together with container classes at more source code places.

    You did not address any of the concerns. You only added suggestions.

    That is not acceptable. You must only submit ideas/proposals that don't break encapsulation.

  • 0 Votes
    8 Posts
    2k Views
    E

    How do you think about the usage of customised constructor implementations for the class “QStandardItem”?

  • 0 Votes
    27 Posts
    6k Views
    VRoninV

    @Christian-Ehrlicher said in Support for QStandardItem proxies?:

    But only when Qt was compiled in debug mode

    Yes, as the docs say using invalid indexes remains undefined behaviour, I am just trying to help users spot these cases

  • 0 Votes
    5 Posts
    1k Views
    E

    Unless you go into very specific obscure cases

    Another software design possibility would be to fiddle with proxies for data models (and their items), wouldn't it?

  • 0 Votes
    27 Posts
    7k Views
    JKSHJ

    @elfring said in Support for constructing QStandardItem objects from QVariant references?:

    I would appreciate if I can reuse existing functionality from a higher level base class.

    Sorry! I just re-read this line and realized you said "higher level base class". In this case, please ignore what I said about choosing pros and cons.

  • 0 Votes
    4 Posts
    2k Views
    VRoninV

    What model are you using? QStandardItemModel had the roles argument working from Qt 5.11 onward. An empty role vector implies "all roles changed"

  • 0 Votes
    5 Posts
    3k Views
    Y

    Thank you @mrjj and @Christian for answer. I am able to make user Checkable.

    class CustomListModel : public QStandardItemModel {
    public:
    Qt::ItemFlags CustomListModel::flags(const QModelIndex & index) const {
    Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index);
    if (index.isValid()) {
    return defaultFlags | Qt::ItemIsUserCheckable;
    }
    return defaultFlags;
    }

    CustomListModel(const int row, const int coloumn) : QStandardItemModel(row, coloumn) { }

    };

    and modification.
    hwListProxyModel->setSourceModel(new CustomListModel (0, 0));