Skip to content
  • 0 Votes
    2 Posts
    237 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
    4 Posts
    378 Views
    Christian EhrlicherC

    But it's in the documentation for e.g. setItem(): The model takes ownership of the item.

  • 0 Votes
    3 Posts
    484 Views
    R

    @Christian-Ehrlicher said in Qt 6.2 QStandardItemModel::setRowCount(0) very slow:

    You should not use setRowCount() in this case but begin/endResetModel().

    Thanks very much! That solved the slowdown.

  • 0 Votes
    5 Posts
    938 Views
    JonBJ

    @Yash001
    When items are removed from a model the view will update to reflect the new state. Widgets you have added via setIndexWidget() which are no longer present will be deleted by Qt infrastructure without you needing to delete them or disconnect from signals.

  • 0 Votes
    4 Posts
    742 Views
    SGaistS

    Yes, you are in charge of writing the GUI part.

  • 0 Votes
    9 Posts
    1k Views
    D

    @SGaist Woah... I have lots to read! Thanks! Gotta dig into proxier more then.

  • 0 Votes
    4 Posts
    799 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
    35 Posts
    7k Views
    E

    I don't understand this question.

    How do you think about information from Cppcheck's forum and issue tracker? Do you care for software aspects which can be discussed there?
  • 0 Votes
    9 Posts
    2k Views
    E

    What further software evolution ?

    You might occasionally find SQL data models more promising, don't you?

  • 0 Votes
    9 Posts
    2k Views
    E

    If you mean outside of answering question here in forum, then no thank you. :)

    I am curious then if you would like to clarify related development topics.

    Do you know any higher level tools which can display structural differences between standard item models in a clear way? Have you got any experiences with “diff views” in this software area?
  • 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
    10 Posts
    6k 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
    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));

  • 0 Votes
    5 Posts
    3k Views
    CybeXC

    @SGaist
    Platform - Linux x86_64
    Qt Version - 5.9.3

    @JNBarchan
    fontHeight produced a integer value +/- 56
    iconHeight produced an integer value ( < fontHeight)

    @VRonin
    The Role's where not the problem. Please see my updated delegate below (kudos for calling it, the delegate being the problem)

    Well this is embarrasing. I did not fully realize what I was coding until I had battled with the delegate all night.

    I understood that I was coding a template, and assumed that on each item which was added, the origin remained at [0,0]. This was not the case as there was an offset added of value specified in the sizeHint (in my case, 56). Thus all my QListView's QStandardItem's were in fact there, but drawn over each other.

    After changing values and experimenting over a long period (a number of hours), I finally came to the desired result, shown below.

    Also, I need to thank scopchanov for his hint into this offset problem

    StackoverFlow question as a reference

    Updated ServerDelegate.cpp

    #include "serverdelegate.h" ServerDelegate::ServerDelegate(QStyledItemDelegate *parent) : QStyledItemDelegate(parent) { fontCountry = QApplication::font(); fontCountry.setBold(true); fontCountry.setPointSize(QApplication::font().pointSize() + 3); fontCity = QApplication::font(); fontCity.setItalic(true); fontCity.setPointSize(QApplication::font().pointSize() - 1); } ServerDelegate::~ServerDelegate(){ } QSize ServerDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const{ Q_UNUSED(index) QSize totalCountrySize = Global::getCountryFlagFromCache(index.data(DataRole::CountryText).toString()).size(); QSize totalSideIcon = QPixmap(":/res/images/premium", "PNG").size(); QFontMetrics fmCountry(fontCountry); QFontMetrics fmCity(fontCity); int fontHeight = (2 * AppGlobal::Style_List_Seperator_Width) + (2 * AppGlobal::Style_List_Text_Item_Margin) + fmCountry.height() + fmCity.height(); int iconHeight = (2 * AppGlobal::Style_List_Seperator_Width) + (totalCountrySize.height() > totalSideIcon.height() ? totalCountrySize.height() : totalSideIcon.height()); int height = (fontHeight > iconHeight) ? fontHeight : iconHeight; int width = option.rect.width(); QSize size = QSize(width, height); return size; } void ServerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{ QStyledItemDelegate::paint(painter, option, index); QFontMetrics fmCountry(fontCountry); QFontMetrics fmCity(fontCity); QRect rec = option.rect; painter->save(); painter->setClipRect(rec); QString countryText = index.data(DataRole::CountryText).toString(); QString cityText = index.data(DataRole::CityText).toString(); QPixmap countryFlag = QPixmap(qvariant_cast<QPixmap>(index.data(DataRole::CountryFlag))); QPixmap sideIcon = qvariant_cast<QPixmap>(index.data(DataRole::SideIconFlag)); // Get a rectangle by size x, y. // With cooridinates [0,0]; [x,0]; [x,y]; [0,y] QRect topLine = option.rect, bottomLine = option.rect; // create top 'seperator' of X px's width, green in color; topLine.setTop(rec.top()); topLine.setLeft(rec.left()); topLine.setRight(rec.right()); topLine.setBottom(rec.top() + AppGlobal::Style_List_Seperator_Width); // 1px down painter->setPen(AppGlobal::Style_List_Seperator_Color); painter->fillRect(topLine, AppGlobal::Style_List_Seperator_Color); painter->drawRect(topLine); // create bottom 'seperator' of X px's width, green in color; bottomLine.setTop(rec.bottom() - AppGlobal::Style_List_Seperator_Width); bottomLine.setLeft(rec.left()); bottomLine.setRight(rec.right()); bottomLine.setBottom(rec.bottom()); // 1px down painter->setPen(AppGlobal::Style_List_Seperator_Color); painter->fillRect(bottomLine, AppGlobal::Style_List_Seperator_Color); painter->drawRect(bottomLine); // create background rectangle QRect content(rec.left(), topLine.bottom(), (rec.right() - rec.left()), (bottomLine.top() - topLine.bottom())); painter->setPen(AppGlobal::Style_List_Background_Color); painter->fillRect(content, ((option.state & QStyle::State_MouseOver) ? AppGlobal::Style_List_Hover_Color : AppGlobal::Style_List_Background_Color )); painter->drawRect(content); // create content rectangles from content container. QRect rectCountryFlag = content, rectSideIcon = content; // create country icon rectangle QSize countryFlagSize = countryFlag.size(); int cFPos = ((rectCountryFlag.bottom() - rectCountryFlag.top()) / 2) - (countryFlagSize.height() / 2) - 8; rectCountryFlag.setTop(rectCountryFlag.top() + cFPos); rectCountryFlag.setBottom(content.bottom() - cFPos); rectCountryFlag.setLeft(AppGlobal::Style_List_Left_Item_Margin - 8); rectCountryFlag.setRight(AppGlobal::Style_List_Left_Item_Margin + 16 + countryFlagSize.width()); painter->drawPixmap(rectCountryFlag, countryFlag); // create side icon rectangle QSize sideIconSize = sideIcon.size(); int siPos = ((rectSideIcon.bottom() - rectSideIcon.top()) / 2) - (sideIconSize.height() / 2) - 4; rectSideIcon.setTop(rectSideIcon.top() + siPos); rectSideIcon.setBottom(content.bottom() - siPos); rectSideIcon.setLeft(rec.width() - (AppGlobal::Style_List_Right_Item_Margin + 8 + sideIconSize.width())); rectSideIcon.setRight(rec.width() - AppGlobal::Style_List_Right_Item_Margin); painter->drawPixmap(rectSideIcon, sideIcon); int textContentLeft = rectCountryFlag.right() + AppGlobal::Style_List_Text_Item_Margin + AppGlobal::Style_List_Left_Item_Margin, textContentTop = content.top() + AppGlobal::Style_List_Text_Item_Margin; const QRect textContent( textContentLeft , textContentTop, (rectSideIcon.left() - AppGlobal::Style_List_Text_Item_Margin) - textContentLeft, (content.bottom() - AppGlobal::Style_List_Text_Item_Margin) - textContentTop); // create country text rectangle QRect rectCountryText = content, rectCityText = content; rectCountryText.setLeft(textContent.left()); rectCountryText.setTop(textContent.top()); rectCountryText.setRight(textContent.right()); rectCountryText.setBottom(textContent.top() + fmCountry.height()); painter->setPen(AppGlobal::Style_Heading_Color); painter->setFont(fontCountry); painter->drawText(rectCountryText, countryText); // create city text rectangle rectCityText.setLeft(textContent.left() + ( 2 * AppGlobal::Style_List_Text_Item_Margin)); rectCityText.setTop(rectCountryText.bottom()); rectCityText.setRight(textContent.right()); rectCityText.setBottom(textContent.bottom() + fmCity.height()); painter->setPen(AppGlobal::Style_SubText_Color); painter->setFont(fontCity); painter->drawText(rectCityText, cityText); // restore painter painter->restore(); }
  • 0 Votes
    3 Posts
    2k Views
    VRoninV

    Put a QSortFilterProxy model in-between. then save from the proxy instead of the main model.

    P.S.
    connect(currentTableHeader, SIGNAL(sectionClicked(int)), this, SLOT(on_sectionClicked(int))); and void mainWidget::on_sectionClicked(int index) are useless. this is the default behaviour of QTableView, you don't have to implement it manually

  • 0 Votes
    9 Posts
    9k Views
    VRoninV

    @IMAN4K said in change QSortFilterProxyModel behaviour for multiple column filtering:

    Answer from stackfverflow : http://stackoverflow.com/questions/39488901/change-qsortfilterproxymodel-behaviour-for-multiple-column-filtering

    This answer is the typical example that lead people to say

    subclassing QSortFilterProxyModel, which would likely have a very limited reusability

    It's bad. the proxy model implementation should not depend on the structure of the underlying data in sourceModel

  • 0 Votes
    2 Posts
    2k Views
    raven-worxR

    @Yohdu said:

    My second and main question is then : how to implement correct drag and drop operations with custom QStandardItem which needs to own custom data ?

    With the standard item widgets/models you can't drag-n-drop custom item roles.
    This makes sense, since the model doesn't know which UserRole+ was set.
    It would need to iterate all possible item-role values when creating the drop-data.

    The only solution i see is to create your own custom model and reimplement the needed drag-n-drop methods. This also give you full control over your data structure storing the data inside the model.
    This is more work, but you will learn a lot and gain some performance (by avoiding the standard-item classes)

  • 0 Votes
    2 Posts
    2k Views
    raven-worxR

    @alizadeh91
    Either you paint it yourself since you already have the QModelIndex at hand:

    QColor color = index.data( Qt::BackgroundColorRole ).toColor();

    or by letting the style paint the stuff. Note that this also paints the selected background.

    style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, widget );
  • 0 Votes
    15 Posts
    8k Views
    halimaH

    @mrjj it works for me thanks :)

  • 0 Votes
    8 Posts
    3k Views
    TrilecT

    Thanks SGaist,
    will tag as solved.