Skip to content
  • 0 Votes
    13 Posts
    328 Views
    Pl45m4P

    @Mark81 said in Catch mouse click on dummy row for QTabelView (returned by proxy but not in real model):

    That's odd, are we seeing the same repo?

    Yes, definitely.

    Now I see 31 open, 28 closed (same as @JonB , still no #62)

    Issue62.png

    Sorry I couldn't resist:
    The movie scene should be well-known :))

    9bli1m.jpg

  • 0 Votes
    2 Posts
    212 Views
    Christian EhrlicherC

    There is no leak. How do you measure? Please provide a minimal, compileable example of the problem.

  • 0 Votes
    2 Posts
    214 Views
    C

    You should call QStyledItemDelegate::paint function inside yours QStyledItemDelegate derived class before painting of icons and text:

    void IconsRenderItemDelegate::paint(QPainter *painter,
    const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
    QStyledItemDelegate::paint(painter, options, index);

    // Draw somethig
    }

  • 0 Votes
    5 Posts
    438 Views
    Christian EhrlicherC

    Do you use Qt6. 7 on win11? Then you are probably using the windows 11 style.

  • 0 Votes
    5 Posts
    310 Views
    P

    @Christian-Ehrlicher said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing:

    ah I understand now , many Thanks bro <3 i will try another solution
    really I Appreciate Your PROFESSIONAL Support <3

  • 0 Votes
    10 Posts
    822 Views
    C

    @Pl45m4 said in QTreeView child of QMainWindow not resizing with main window:

    Remove the current layout and the ElementView. Drag a new ElementView straight on the centralWidget and then rightclick and "lay out".

    I was doing this, but I misinterpreted what the rightclick applied to. I thought it applied to the new Element View I dragged onto the centralWidget, and its "Lay out" menu had most everything disabled. When I tried rightclicking on the centralWidget outside of the ElementView, its menu had the selections all available.

    All is working now and I have removed my resizeEvent().

    @Pl45m4 and @JonB - All comments are much appreciated!

  • 0 Votes
    3 Posts
    193 Views
    C

    @Christian-Ehrlicher said in QTableView with QAbstractTableModel derrived class not displaying data:

    Elements

    I don't see where you fill this container.

    Sorry, I should have mentioned that Elements is being filled, and has been tested. I was originally using a QListView with QStringListModel which worked to show that Elements was being filled. When I switched to QTableView and QAbstractTableModel I had added a debug statement to rowCount() to also confirm that Elements was filled.

    void RailDocModel::operator<<( LayoutObject * NewElement ) { Elements << NewElement; }

    And here you're missing some important signals: https://doc.qt.io/qt-6/model-view-programming.html#inserting-and-removing-rows

    That pointed me to what I was missing. Changing operator<<() to this was the solution:

    void RailDocModel::operator<<( LayoutObject * NewElement ) { beginInsertRows( QModelIndex(), Elements.count(), Elements.count() ); Elements << NewElement; endInsertRows(); }

    I had tried adding beginInsertRows() and endInsertRows() recently, but had used nullptr as the first parameter to beginInsertRows() instead of QModelIndex().

  • Complex table design

    Solved General and Desktop
    2
    0 Votes
    2 Posts
    258 Views
    SGaistS

    Hi,

    You could check KDE's Kontact application. If I remember correctly they have a journal part that might be of interest.

  • 0 Votes
    4 Posts
    324 Views
    R

    From what I've seen online, the QValidator approach requires subclassing QItemDelegate and it's setData() method. How is this different from the last point suggested ?

  • 0 Votes
    3 Posts
    377 Views
    B

    @SGaist This is the solution! Thank you very much. Below is my new setData() and TextEdited()

    setData()

    bool SummaryModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { SetSummaryQuantity(value.toInt()); emit dataChanged(index,index); return true; } else { return false; } return false; }

    TextEdited()

    void QueriesCreator::on_quantityGeneralInformationLineEdit_textEdited(const QString &arg1) { calculations.SetMaterialQuantity(ui->quantityGeneralInformationLineEdit->text().toInt()); CalculateMaterialCostInZloty(); summaryModel->setData(ui->summaryDefaultTableView->model()->index(6,0),ui->quantityGeneralInformationLineEdit->text().toInt(),Qt::EditRole); }

    and of course the data()

    QVariant SummaryModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { //Quantity if (index.row() == 0 && index.column() == 0) return QString("50"); if (index.row() == 2 && index.column() == 0) return QString("100"); if (index.row() == 4 && index.column() == 0) return QString("1000"); if (index.row() == 6 && index.column() == 0) return GetSummaryQuantity(); //Currency- byc w moze w przyszlosci zmienic na inne if (index.row() == 0 && index.column() == 1) return QString("PLN"); if (index.row() == 1 && index.column() == 1) return QString("EUR"); if (index.row() == 2 && index.column() == 1) return QString("PLN"); if (index.row() == 3 && index.column() == 1) return QString("EUR"); if (index.row() == 4 && index.column() == 1) return QString("PLN"); if (index.row() == 5 && index.column() == 1) return QString("EUR"); if (index.row() == 6 && index.column() == 1) return QString("PLN"); if (index.row() == 7 && index.column() == 1) return QString("EUR"); //Price Placeholders //Material if (index.row() == 0 && index.column() == 2) return QString("0,00"); if (index.row() == 1 && index.column() == 2) return QString("0,00"); if (index.row() == 2 && index.column() == 2) return QString("0,00"); if (index.row() == 3 && index.column() == 2) return QString("0,00"); if (index.row() == 4 && index.column() == 2) return QString("0,00"); if (index.row() == 5 && index.column() == 2) return QString("0,00"); if (index.row() == 6 && index.column() == 2) return QString("0,00"); if (index.row() == 7 && index.column() == 2) return QString("0,00"); //Machining if (index.row() == 0 && index.column() == 3) return QString("0,00"); if (index.row() == 1 && index.column() == 3) return QString("0,00"); if (index.row() == 2 && index.column() == 3) return QString("0,00"); if (index.row() == 3 && index.column() == 3) return QString("0,00"); if (index.row() == 4 && index.column() == 3) return QString("0,00"); if (index.row() == 5 && index.column() == 3) return QString("0,00"); if (index.row() == 6 && index.column() == 3) return QString("0,00"); if (index.row() == 7 && index.column() == 3) return QString("0,00"); //Diference if (index.row() == 0 && index.column() == 4) return QString("0,00"); if (index.row() == 1 && index.column() == 4) return QString("0,00"); if (index.row() == 2 && index.column() == 4) return QString("0,00"); if (index.row() == 3 && index.column() == 4) return QString("0,00"); if (index.row() == 4 && index.column() == 4) return QString("0,00"); if (index.row() == 5 && index.column() == 4) return QString("0,00"); if (index.row() == 6 && index.column() == 4) return QString("0,00"); if (index.row() == 7 && index.column() == 4) return QString("0,00"); } if(role==Qt::TextAlignmentRole) { return Qt::AlignCenter; } return QVariant(); }

    Now It works as I expect. Thanks and Have a good day!

  • 0 Votes
    1 Posts
    175 Views
    No one has replied
  • 0 Votes
    8 Posts
    4k Views
    R

    @ChrisW67 Thanks ! The resizing works but screen.availableGeometry().size() is giving the incorrect size (much too big). I tried a variety of other ways but can't seem to get the correct available size even when running it after the widget is displayed using a timer as suggested.

  • 0 Votes
    7 Posts
    1k Views
    R

    @jsulm said in QTableView clicked() not triggering when dragging and selecting a range of data in the table?:

    @R-P-H Mouse click means that mouse button was pressed AND released over same widget. Pressing mouse button down over one widget and releasing it over another isn't a click.
    You can use https://doc.qt.io/qt-6/qabstractitemview.html#pressed

    pressed() worked for me. Thanks !

  • 0 Votes
    10 Posts
    2k Views
    SGaistS

    The short version would be to add a set_i2c_data method to your model, update the data frame in it and then emit the dataChanged signal as last step of that method.

  • 0 Votes
    2 Posts
    269 Views
    Axel SpoerlA

    Could you share a minimal example please?

  • 0 Votes
    25 Posts
    3k Views
    C

    @CuriousPan I have fixed the issue.
    I used pretty dirty, but working trick: set Qt::AlignedCenter right in the delegate:

    void CenteredCheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; const QWidget *widget = option.widget; initStyleOption(&opt, index); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget); if (opt.features & QStyleOptionViewItem::HasCheckIndicator) { switch (opt.checkState) { case Qt::Unchecked: opt.state |= QStyle::State_Off; break; case Qt::PartiallyChecked: opt.state |= QStyle::State_NoChange; break; case Qt::Checked: opt.state |= QStyle::State_On; break; } auto rect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, widget); opt.rect = QStyle::alignedRect(opt.direction, Qt::AlignCenter/*index.data(Qt::TextAlignmentRole).value<Qt::Alignment>()*/, rect.size(), opt.rect); opt.state = opt.state & ~QStyle::State_HasFocus; style->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &opt, painter, widget); } else if (!opt.icon.isNull()) { // draw the icon QRect iconRect = style->subElementRect(QStyle::SE_ItemViewItemDecoration, &opt, widget); iconRect = QStyle::alignedRect(opt.direction, Qt::AlignCenter/*index.data(Qt::TextAlignmentRole).value<Qt::Alignment>()*/, iconRect.size(), opt.rect); QIcon::Mode mode = QIcon::Normal; if (!(opt.state & QStyle::State_Enabled)) mode = QIcon::Disabled; else if (opt.state & QStyle::State_Selected) mode = QIcon::Selected; QIcon::State state = opt.state & QStyle::State_Open ? QIcon::On : QIcon::Off; opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state); } else { QStyledItemDelegate::paint(painter, option, index); } } bool CenteredCheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_ASSERT(event); Q_ASSERT(model); // make sure that the item is checkable Qt::ItemFlags flags = model->flags(index); if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled) || !(flags & Qt::ItemIsEnabled)) return false; // make sure that we have a check state QVariant value = index.data(Qt::CheckStateRole); if (!value.isValid()) return false; const QWidget *widget = option.widget; QStyle *style = option.widget ? widget->style() : QApplication::style(); // make sure that we have the right event type if ((event->type() == QEvent::MouseButtonRelease) || (event->type() == QEvent::MouseButtonDblClick) || (event->type() == QEvent::MouseButtonPress)) { QStyleOptionViewItem viewOpt(option); initStyleOption(&viewOpt, index); QRect checkRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, widget); checkRect = QStyle::alignedRect(viewOpt.direction, Qt::AlignCenter/*index.data(Qt::TextAlignmentRole).value<Qt::Alignment>()*/, checkRect.size(), viewOpt.rect); QMouseEvent *me = static_cast<QMouseEvent *>(event); if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos())) return false; if ((event->type() == QEvent::MouseButtonPress) || (event->type() == QEvent::MouseButtonDblClick)) return true; } else if (event->type() == QEvent::KeyPress) { if (static_cast<QKeyEvent *>(event)->key() != Qt::Key_Space && static_cast<QKeyEvent *>(event)->key() != Qt::Key_Select) return false; } else { return false; } Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt()); if (flags & Qt::ItemIsUserTristate) state = ((Qt::CheckState)((state + 1) % 3)); else state = (state == Qt::Checked) ? Qt::Unchecked : Qt::Checked; return model->setData(index, state, Qt::CheckStateRole); }

    Thanks everyone who took part in the discussion.

  • 0 Votes
    1 Posts
    464 Views
    No one has replied
  • 0 Votes
    7 Posts
    1k Views
    SGaistS

    Hi,

    You have the model index, so if it's the left most one, draw the left round corners and if it's the right most one, draw the right rounded corner.

    The other option is to use one delegate for the first and last column to do the special painting. Note that this is not the correct solution if your users can reorder the columns.

  • 0 Votes
    4 Posts
    349 Views
    F

    I fixed it with:

    setStyleSheet("QHeaderView::section{ padding-left: 4px; padding-top: 1; padding-bottom: 1; }");