Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Need help on QAbstractItemView/QAbstractItemDelegate.
Forum Updated to NodeBB v4.3 + New Features

Need help on QAbstractItemView/QAbstractItemDelegate.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 453 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LiamMadyam
    wrote on last edited by LiamMadyam
    #1

    Hi, I'm new to programming and Qt, pardon me if I'm asking anything stupid. I have a doubt regarding QListView. I have a populated model with 3 keys, I need to add Radio Buttons to each index. I initially used QListView which couldn't help me achieve that. I realized I needed a delegate to do that. QTreeView usually uses QStyledItemDelegate so what should I do to have a list view with radio buttons. I read on Qt forum which said I need to use QAbstractItemView, so I was wondering if I need to QAbstractItemView instead of QListView or subclass QAbstractItemDelegate and then use QAbstractItemView? If I'm subclassing which function do I need to use. https://trackeasy.fun/usps/ https://showbox.tools/ https://speedtest.vet/

    raven-worxR 1 Reply Last reply
    0
    • L LiamMadyam

      Hi, I'm new to programming and Qt, pardon me if I'm asking anything stupid. I have a doubt regarding QListView. I have a populated model with 3 keys, I need to add Radio Buttons to each index. I initially used QListView which couldn't help me achieve that. I realized I needed a delegate to do that. QTreeView usually uses QStyledItemDelegate so what should I do to have a list view with radio buttons. I read on Qt forum which said I need to use QAbstractItemView, so I was wondering if I need to QAbstractItemView instead of QListView or subclass QAbstractItemDelegate and then use QAbstractItemView? If I'm subclassing which function do I need to use. https://trackeasy.fun/usps/ https://showbox.tools/ https://speedtest.vet/

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @LiamMadyam
      generally the cells are just painted in the delegate.
      there is setIndexWidget() method on the QListView.
      Or if checkboxes are also ok you can set the items in the model checkable and the default delegate will paint checkboxes beside the text

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Normally you would use QStyledItemDelegate
        Like seen here for a CheckBox delegate.
        https://github.com/pierreet/BooleanCheckBoxDelegate/blob/master/BooleanCheckBoxDelegate.h

        You need to implement the following functions.

        class BooleanCheckBoxDelegate : public QStyledItemDelegate
            QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
            void setEditorData(QWidget *editor, const QModelIndex &index) const
            void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
            void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
            void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
        };
        
        

        Do note that a checkbox delegate is not needed as it can do it by itself but to use for RadioButton,
        only requires changing QCheckBox used to QRadioButton.

        But, radio buttons is exclusive (one can be selected ) and if you need that you have to check the other
        rows in setModelData and act accordingly.

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved