Skip to content
QtWS25 Last Chance
  • Tree View with varying column counts

    Unsolved General and Desktop qtreeview treemodel model model-view
    5
    0 Votes
    5 Posts
    2k Views
    JonBJ
    @hieuht said in Tree View with varying column counts: First, the child's count cannot more than the parent's count. Hmm, I did not see that mentioned. Indeed https://doc.qt.io/qt-6/qabstractitemmodel.html#columnCount says: In most subclasses, the number of columns is independent of the parent. Maybe it's a limitation on QTreeView rather than on the model? Second, the child's column size depend on the parent's size like the following picture. It looks like the child is only really using the parent's existing columns, just (according to you) it can only use the same number or fewer. Understandable, but not what your picture shows. Could you provide an example of using delegate to handle this? Quite beyond me! This is not just a simple delegate, it's virtually the drawing of a complete new table. @SGaist sometimes picks out something which KDE has added in https://api.kde.org/frameworks/index.html. You might look through that, maybe there is something there for you?
  • 0 Votes
    3 Posts
    832 Views
    L
    @mrjj Thanks I got it to work. ui->setupUi(this); ui->tableWidget->setColumnCount(2); ui->tableWidget->setRowCount(numberSet.size()); ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); QStringList tableHeader = {"Number", "Result"}; ui->tableWidget->setHorizontalHeaderLabels(tableHeader); int rowCounter = 0; for(int i : numberSet) { ui->tableWidget->setItem(rowCounter, 0, new QTableWidgetItem(QString::number(i))); ui->tableWidget->setItem(rowCounter, 1, new QTableWidgetItem(someConversion(i))); rowCounter++; }
  • 0 Votes
    7 Posts
    2k Views
    VRoninV
    @Arthur-Araruna said in Replicate the contents of the current selected item in QTableView: both column and row indices All you need to do is replace currentRowChanged with currentIndexChanged
  • 0 Votes
    4 Posts
    2k Views
    S
    Finaly I have finished my little example! Previous version have been really buggy in items move. So I have to subclass from QAbstractItemModel. Many thanks to @Patou355 with his solution. NB I haven't deal with mousePressEvent() yet.
  • 0 Votes
    12 Posts
    6k Views
    T
    @steveq Thanks so much! Were u able to figure out how to make URLs, sandwiched between other text, clickable? e.g. if message was: Hey, checkout this website: http://forum.qt.io, its really cool! In that only the url should be click, and maybe show hover effect as well. I read some suggestions about using mouse hit-testing to achieve that, but it seems like a lot of work. Another thing I really wanted to do was to make text selectable, but even that seems complicated.
  • Dynamically change a component

    Solved QML and Qt Quick dynamic qml model-view load
    5
    0 Votes
    5 Posts
    4k Views
    M
    Ok, nice, these three answers (StackView / StackLayout / Loader + Component) were what I was looking for. I tried each one and I think I'll stick with the StackView and the replace method as it's easy to have a fading transition with it. And I've already found a use to improve my code for the Loader so I also thank you for that. Thx for the help.
  • 0 Votes
    1 Posts
    3k Views
    No one has replied
  • 0 Votes
    13 Posts
    4k Views
    O
    thanks. i will try it :)
  • 0 Votes
    11 Posts
    8k Views
    HaithamH
    @VRonin Can you please provide an example or something to follow? Because I am still a newbie at both Qt and QML. Sorry for bothering you with my many questions. Update: as you can see in the code, I change the state of the delegate through the mouse area in the delegate (it's commented out in the code). I was using it to test the states, now I've noticed another thing; Whenever I collapse the parent Item and then expand it, the previous states are not saved....does this have to do anything with what you mentioned?
  • 0 Votes
    3 Posts
    1k Views
    VRoninV
    In 90% of the cases you can use QStandardItemModel instead of going through the minefield that is subclassing an abstract model. My advice is just to use that "universal model" instead of a custom one. If you really, really want to customise it as performance of QStandardItemModel is a problem then make sure you run your model through the Model Test (needs just a couple of trivial fixes to work on Qt5) that will tell you if you did everything as you were supposed to or you fell in the countless pitfalls of model subclassing
  • 0 Votes
    9 Posts
    10k 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!
  • 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
    4 Posts
    2k Views
    raven-worxR
    @NIXIN class MySortFilterProxyModel : public QSortFilterProxyModel { Q_OBJECT Q_PROPERTY(bool FilterEnabled READ isFilterEnabled WRITE setFilterEnabled ) public: virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const { if( !m_IsFilterEnabled ) return true; // your filtering code here } bool isFilterEnabled() const { return m_IsFilterEnabled }; void setFilterEnabled( bool enabled ) { if( m_IsFilterEnabled != enabled ) { m_IsFilterEnabled = enabled; this->invalidate(); } } private: bool m_IsFilterEnabled;
  • QAbstractListModel as property

    Solved General and Desktop qabstractlistmo qml c++ qt5.7 model-view
    3
    0 Votes
    3 Posts
    4k Views
    romsharkovR
    @SGaist returning a pointer in the getter and defining the Q_PROPERTY as a pointer to the list worked out fine! Thanks for that!
  • Updating a proxy model

    Unsolved General and Desktop model-view
    8
    0 Votes
    8 Posts
    3k Views
    SGaistS
    Like I said, without seeing any code I can't comment on whether the wrong index is being used or something else is going on.
  • Transforming and filtering a model

    Solved General and Desktop model-view
    6
    0 Votes
    6 Posts
    2k Views
    SGaistS
    You don't need all of this. Just use the top-most index. Modifying its content will propagate it back to the bottom index.
  • 0 Votes
    5 Posts
    24k Views
    SGaistS
    Hi, You can try with the QHeaderView::minimumSectionSize property
  • 0 Votes
    2 Posts
    1k Views
    mrjjM
    @tokafr said: Mydelegate *delegate = new Mydelegate; hi, i might miss something but why dont you just create another instance? Mydelegate *delegate2= new Mydelegate; view2 -> setItemDelegate(delegate2); Normally a delegate (instance) is not shared between views as its not intended.
  • 0 Votes
    9 Posts
    10k Views
    Z
    I finally managed to get custom colors. I gave my QTreeView an object name to be able to write this in CSS: m_treeView->setObjectName("MyTreeView"); m_treeView->setStyleSheet("QTreeView#MyTreeView::item {color: none;}"); basically now my model controls text color through Qt::ForegroundRole regardless of the application's CSS. I feel like it's the wrong place to put theming, but it works for me at the moment. Well... until we decide to have different themes :-°
  • [SOLVED]QTableModel crashes on headerData

    Unsolved General and Desktop qabstracttablem model-view
    10
    1 Votes
    10 Posts
    4k Views
    mrjjM
    @RDiGuida Ok, so cnamMet would run out of scope and be deleted (when function ended) but sounds like data.rnames should have been working. Well if a copy on creation time works for you, its a wrap :)