Skip to content
  • 0 Votes
    5 Posts
    5k Views
    M

    After much experimentation and some luck I found the solution to this mystery.

    On startup I had

    ui->tvRMA->horizontalHeader()->restoreState(...);

    which restored invalid information from previous sessions with different layouts. Clearing the database of previous sessions brought back the proper behaviour.

    Mike

  • 0 Votes
    4 Posts
    3k Views
    kshegunovK

    @Nosba said:

    but how can I know when the user is editing a cell?

    I don't know, and that wasn't your original question. One thing you could try is to subclass the view and reimplement the edit() method from where you can emit a signal that notifies you when editing has started. I hope that helps.

    Kind regards.

  • 0 Votes
    13 Posts
    5k Views
    S

    @raven-worx
    Jackpot! Thank you so much for your help!! Finally I did it using QFileSystemWatcher.
    Thumbs up for you (if possible?!). :)

    Thread marked as solved.
    Cheers

  • 0 Votes
    7 Posts
    3k Views
    A

    Sure. Thanks .

  • 0 Votes
    14 Posts
    7k Views
    SGaistS

    QTableWidget already has an internal model otherwise it's a QTableView.

  • 0 Votes
    10 Posts
    6k Views
    HunterMetcalfeH

    @raven-worx

    @raven-worx said:

    do you really insert columns? or rows?
    ANd do you call the signals with the correct indexes?

    Well the columns are properly updated with the correct information after the beginInsertColumns and endInsertColumns, so yes I am 100% certain the view is being updated when the model changes. I'm also certain that the sort and delete work as both functions are reflective in the view.

    yes it's not necessary to call dataChanged() with an invalid index. Rather you should call it with the index which data has cahnged obviously.

    I understand that, again this code was not written by me, I'm simply attempting to solve an issue that was discovered. Moving on from both of your points we still have yet to find a solution. The issue is with the selection of data, not the addition, subtracting or sorting thereof. I believe the issue had to do with the Update function (as a hunch) perhaps it is a mutex locking issue in the model?

  • 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
    4 Posts
    5k Views
    B

    I think i've found a solution.

    First, i install an eventFilter in my custom editor widget B on the internal spinbox :

    internalSpinbox->installEventFilter(this);

    Then, i implement eventFilter to treat the events on the spinbox and duplicate them to the parent:

    bool AbstractRatioQuantitySpinbox::eventFilter(QObject *object, QEvent *event) { // cf http://stackoverflow.com/questions/12145522/why-pressing-of-tab-key-emits-only-qeventshortcutoverride-event if (event->type() == QEvent::KeyPress) { auto keyEvent = static_cast<QKeyEvent *>(event); if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) { QApplication::postEvent( this, new QKeyEvent(keyEvent->type(), keyEvent->key(), keyEvent->modifiers())); return true; } } else if (event->type() == QEvent::FocusOut) { auto focusEvent = static_cast<QFocusEvent *>(event); QApplication::postEvent(this, new QFocusEvent(focusEvent->type(), focusEvent->reason())); return false; } return QWidget::eventFilter(object, event); }
  • 0 Votes
    5 Posts
    2k Views
    S

    @Sudo007 said:

    hi
    I have created a class customDelegate (inherits QItemDelegate) in my Qt applicatrion and i created setEditor() function.But the delegate is not visible in the QTableView , untill i click on the row.
    How to fix the issue?

    How did you implement the paint() in your custom delegate ? As you are adding different widget in each cell, you need to paint a fake widget (QPushButton) using QApplication::style()->drawControl(QStyle::CE_PushButton, &btn,painter); where btn is QStyleOptionButton, then in createEditor() you create an instance of QPushButton.

  • 0 Votes
    3 Posts
    3k Views
    the_T

    @raven-worx
    Hi,

    thanks for your reply and information.
    Will mark it as "solved", as it is only a minor but interesting styling "issue" :)

  • 0 Votes
    2 Posts
    897 Views
    raven-worxR

    @tokafr
    if i got you correct you want to drag&drop from your Qt application to the filesystem?
    If so take a look here.

  • 0 Votes
    2 Posts
    1k Views
    Chris KawaC

    Można użyć modelu proxy, który będzie interpretował jakieś dane (np. "0" i "1") jako checkbox, np.

    class MyProxy : public QIdentityProxyModel { public: MyProxy(QObject* parent) : QIdentityProxyModel(parent) {} QVariant data(const QModelIndex& index, int role) const override { if (role == Qt::CheckStateRole && index.column() == 0) { QString str_value = QIdentityProxyModel::data(index, Qt::DisplayRole).toString(); return (str_value == "1") ? Qt::Checked : Qt::Unchecked; } return QIdentityProxyModel::data(index, role); } bool setData(const QModelIndex& index, const QVariant& value, int role) override { if (role == Qt::CheckStateRole && index.column() == 0) { QString str_value = (value.toInt() == Qt::Checked) ? "1" : "0"; return QIdentityProxyModel::setData(index, str_value, Qt::EditRole); } else return QIdentityProxyModel::setData(index, value, role); } Qt::ItemFlags flags(const QModelIndex& index) const override { Qt::ItemFlags f = QIdentityProxyModel::flags(index); if (index.column() == 0) f |= Qt::ItemIsUserCheckable; return f; } };

    oczywiście numer kolumny i dane rozpoznawane jako "zaznaczony" można sobie dostosować.
    Takiego modelu można użyć potem tak:

    QSqlTableModel* model = new QSqlTableModel(parent, database); MyProxy* proxy = new MyProxy(parent); proxy->setSourceModel(model); tableView->setModel(proxy);
  • 0 Votes
    5 Posts
    3k Views
    P

    @thEClaw
    Well, since you were worried about how clean your solution was, I thought I should come up with a nastier hack: -): I'm storing the ints in my map as negative numbers and then I retrieve the "real" numbers in the model's data() method like this:

    ... if (item.column() == 2) { int fake = recordsMap.keys().at(item.row()); return abs(fake); } ...

    At least everything works and displays fine now.

    I fiddled a lot with visualIndex() and logicalIndex() but couldn't find a way to make this work, so I'm keeping this for the time being. Thanks anyway for your suggestion!

  • 0 Votes
    2 Posts
    5k Views
    S

    Further investigation into the issue has revealed that HiearchicalHeaderView re-implements the header views sections, and there is no relationship between the QHeaderView notion of sections, and the HiearchicalHeaderView notion of sections.

    As a result, the following calls are available, but return incorrect data.

    QHeaderView::count() returns 0
    QHeaderView::sectionSize(int) returns 0
    QHeaderView::logicalIndex(int) returns -1
    etc...

    The upshot of this is that there is a significant amount of work required in HierarchicalHeaderView in order to make in feature complete, and that the way it is currently implemented is not symbiotic with QHeaderView

    That essentially leaves 2 questions.

    Does an open source feature-complete hierarchical header view exist? Is there a way to easily implement hierarchical headers in a QHeaderView?
  • 0 Votes
    15 Posts
    8k Views
    halimaH

    @mrjj it works for me thanks :)

  • 0 Votes
    2 Posts
    1k Views
    RatzzR

    @MhM93
    You can use button in each row of QTableView as shown in this example.

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi and welcome to devnet,

    Something's not clear. Do you have anything that is shown at all ?

    In your code excerpt there's nothing related to the handling of the row/column count for example. Also your QTableView doesn't belong to any layout so are you resizing it somewhere ?

  • 0 Votes
    9 Posts
    2k Views
    B

    OK here we go. All the files are in DropBox and should be available via:

    https://www.dropbox.com/sh/7hzpv4k021k50y2/AACobsU7FpvbllB_56UUffP5a?dl=0

    I have hardcoded a minimal data set which is accessed by clicking on the Load button - so as to keep the system as intended. No other buttons work.

  • 0 Votes
    2 Posts
    2k Views
    mrjjM

    Hi
    What about using
    http://doc.qt.io/qt-5/qabstractitemview.html#currentChanged
    You get new QModelIndex which has
    http://doc.qt.io/qt-5/qmodelindex.html#column

    So when u get this signal, u can check if the "watched" col and do your thing.

    You also get last QModelIndex , so you can check if a cell is "left" that way.
    Meaning its the last ModelIndex.

  • 0 Votes
    1 Posts
    665 Views
    No one has replied