Skip to content
Qt 6.11 is out! See what's new in the release blog
  • 0 Votes
    5 Posts
    3k Views
    SebastianMS
    Cool, that's what I was looking for.
  • 1 Votes
    2 Posts
    2k Views
    C
    I eventually managed to fix this by implementing updateEditorGeometry and calling editor->setGeometry(option.rect);. I should have looked into base class member functions sooner!
  • 0 Votes
    2 Posts
    2k Views
    S
    Ok, I have figured it out by myself. The key was looking at the comboBoxModel->data and getting the index from rows and coloumns. That's my solution: void comboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if(QComboBox *cb = qobject_cast<QComboBox*>(editor)) { QString cbText = cb->currentText(); int vpe_index = -1; for (int row = 0; row < comboBoxModel->rowCount() ; row++) { if (comboBoxModel->data(comboBoxModel->index(row, 0)) == cbText){ vpe_index = comboBoxModel->data(comboBoxModel->index(row, 1)).toInt(); } } if (vpe_index == -1) { qDebug() << "Index not found"; } else { qDebug() << "Index set: " << model->setData(index, vpe_index, Qt::EditRole); } } else { QStyledItemDelegate::setModelData(editor, model, index); } }
  • 0 Votes
    5 Posts
    4k Views
    L
    @JonB Thank you for your explanation. I understand what i need to do, but i need a little help in making the right signals and slots. My project was setup using the "Using C++ Models in QML {tutorial}" as a guide. here the ToDoList class is set as the data in ToDoListModel class. In the ToDoList Calss there are: 1.appendItem() function, which emits the signals preItemAppended() and postItemAppended() 2.removeItem() funciton, which emits the signals preItemRemoved() and postItemRemoved() [these work fine] 3.similar to the appendItem() and removeItem() I am trying to make a setItemAt() function that will modify the existing data. but there was no steps in the tutorial to indicate how i could notify the model to emit the dataChanged() signal. I tried making my own signal in the data class and a slot in model class but i couldn't figure out how to connect them. the main function has a ToDoList object but no ToDoListModel object (ToDoListModel is just registered to qml). i am only familiar with using the connect(*sender,signal,*receiver, slot) function to connect. I suspect that it has something to do with the 'Q_PROPERTY(ToDoList *list READ list WRITE setList NOTIFY listChanged)' line in the ToDoListModel header file. following the tutorial I removed the NOTIFY listChanged part. summary:which signal do i need to emit from the data class(ToDoList) to have the model class (ToDoListModel) emit the dataChanged() signal?
  • 0 Votes
    14 Posts
    8k Views
    L
    ok, the template solution is also working here. Thanks a lot for your help!
  • 0 Votes
    4 Posts
    4k Views
    VRoninV
    Actually, since the base class already has a virtual destructor you can just remove the destructor of your derived altogether
  • 0 Votes
    2 Posts
    2k Views
    Chris KawaC
    I'm doing something similar in sort of objects property tree. It works pretty well for large number of items. Definitely a massive win over a widget per item approach. One difference to your approach is that I don't use grab(), but instead have the editors created by the delegate a static drawing function that uses QStyle::drawControl and friends to draw an image of itself. This is because I don't want to instantiate all the editor widgets upfront to grab them (I have a bunch of them and it takes time). It's sort of a trade-off because it can get out of sync with the actual widget look. Whether this is something you'd be interested in or not is up to you, but the general idea of drawing an image is a valid one.
  • Delegate that paint entire widget area

    Unsolved General and Desktop modelview delegate painter
    4
    0 Votes
    4 Posts
    3k Views
    mrjjM
    Hi Mr @VRonin suggested we looked at http://doc.qt.io/qt-5/qabstractscrollarea.html#maximumViewportSize so maybe yo u need to subclass view and return full area.
  • 0 Votes
    4 Posts
    3k Views
    SGaistS
    Did you already checked the bug report system to see if there was something related ? If not, please consider opening a new report providing a minimal compilable example showing the behaviour.
  • Extended Custom Completer Example

    Unsolved General and Desktop completer delegate
    2
    1 Votes
    2 Posts
    3k Views
    ?
    I made a small update on the code. In the delegate I reworked the highlight section: QAbstractTextDocumentLayout::PaintContext ctx; QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4); painter->save(); painter->translate(textRect.topLeft()); painter->setClipRect(textRect.translated(-textRect.topLeft())); // Highlighting text if item is selected if (optionV4.state & QStyle::State_Selected){ ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); QStyleOptionViewItem toolTip = option; initStyleOption(&toolTip, index.sibling(index.row(),2)); QToolTip::showText(QPoint(textRect.right() + 15, textRect.top()), toolTip.text ); } doc.documentLayout()->draw(painter, ctx); painter->restore(); This gives me a nice tool tip but not at the right location. I want it next to the completer but I cannot figure out how to get the coordinates. Since the delegate is not a widget I cannot use this->maptoglobal(). Any ideas on how I could position the tool tip next to the highlighted element?
  • 0 Votes
    9 Posts
    12k Views
    HaithamH
    @6thC did your application consist of a tree and you could apply a delegate to specific items? because that's where I'm stuck now. I am still researching on how to connect QML with C++ and as usual if I figured out a way of applying delegates to specific items based on a logical condition (like your warning and maximum states), I will let you know. Thanks for your time bro!
  • Delegate

    Unsolved General and Desktop delegate
    7
    0 Votes
    7 Posts
    2k Views
    SGaistS
    Great ! What did you implement ? Also, since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum uses may know a solution has been found :)
  • QTableWidget: Set specific row's color

    Unsolved General and Desktop qtablewidget qtableview delegate
    10
    0 Votes
    10 Posts
    29k Views
    S
    @VRonin hey it works. I created a separate qt project and it's working there. I will see if I am doing something wrong in my project. Actually the row to which I am trying to set a background color also has some color set to it in table widget stylesheet. Also tablewidget items also have a background color. I will check there. Thanks again.
  • 0 Votes
    4 Posts
    4k Views
    p3c0P
    @tamlong0205 I think most of this can be done from C++ side. You can add a function in the model which can return what type is the data for current index. This function will be called from QML and depending upon its value use a Loader to load the specific delegate. Perhaps setting currentIndex in Component.onCompleted handler ? Create a C++ function which will store in info in the model itself i.e When you change the index in ComboBox call this function and update the value there and may be maintain a role to store this update.
  • 0 Votes
    6 Posts
    4k Views
    VRoninV
    Any reason why you can't use QStandardItemModel? in that case subclass QStyledItemDelegate and reimplement paint void QStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { Q_ASSERT(index.isValid()); QStyleOptionViewItem opt = option; initStyleOption(&opt, index); ///////////////////////////////////// // Set the background based on the content if(index.data().toInt()==1) opt.backgroundBrush = QBrush(Qt::red); ///////////////////////////////////// const QWidget *widget = option.widget; QStyle *style = widget ? widget->style() : QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget); }
  • QML ListView memory performance

    Solved QML and Qt Quick listview delegate memory performance
    3
    0 Votes
    3 Posts
    4k Views
    KroMignonK
    @jpnurmi Thank's a lot! That's it :) Now everything works like a charm :) You saved my day!
  • Propagate TAB key from delegate to custom editor

    Unsolved General and Desktop delegate event
    5
    0 Votes
    5 Posts
    3k Views
    VRoninV
    Just to understand, is the delegate (assume it's a delegate with 2 line edits) in editing mode (e.g. after you type in the first line edit you want to go in the second) or just in paint mode (e.g. you want to press tab and go in the first lineedit of the following cell)?
  • Model views with pagination

    Unsolved QML and Qt Quick model delegate grid page navigation
    8
    0 Votes
    8 Posts
    8k Views
    C
    @Mark81 Even in JavaScript you have two models, you just don't typically think of it that way: model 1: the database, model 2: the results on the client side. Here, you have two models: 1 - the database, 2 - the QML side. So what you need to do is create a paginated model using LIMIT/OFFSET queries.
  • 0 Votes
    4 Posts
    3k Views
    p3c0P
    @Mark81 If index is 0 then don't start the animation. Well something like: property int myIndex : 0 function animate(idx) { listAnimation.running = false var pos = list.contentY; var destPos; list.positionViewAtIndex(idx, ListView.Beginning); destPos = list.contentY; listAnimation.from = pos; listAnimation.to = destPos; listAnimation.running = true; } Timer { ... onTriggered: { if(myIndex==0) list.positionViewAtIndex(myIndex,ListView.Beginning); else animate(myIndex) myIndex++ if(myIndex==list.count-1) myIndex = 0 } }
  • What is QHeaderView default delegate.

    Unsolved General and Desktop qheaderview qtableview delegate
    2
    0 Votes
    2 Posts
    2k Views
    SGaistS
    HI, No it's not. You have the explanation here