When using Qtableview or qtablewidget, sometimes we don't want to select a dummy box, we can implement a itemdelegate, rewrite Drawfocus () and Drawcheck () two virtual functions, and then call Qabstractitemvie W's setitemdelegate () passes the custom Itemdelegate object to Qtableview. It is important to note that Qabstractitemview does not delete the itemdelegate that you have set up for it and requires the developer to delete it at the appropriate time.
The following is an example of the Rowdelegate code:
#include <qitemdelegate>class rowdelegate:public qitemdelegate{public: rowdelegate (QObject * parent = 0): Qitemdelegate (parent) { } virtual void Drawfocus (Qpainter *painter, const Qstyleoptionviewitem & option, const qrect &rect) const { } virtual void Drawcheck (Qpainter *painter, const Qstyleoptionviewitem &option, const qrect &rect, qt::checkstate State) const { }};
As you can see, the Drawfocus () and the Drawcheck () of the Rowdelegate class do not work, and thus achieve the purpose.
For Qlistview or Qlistwidget, the above code can also be used to remove the selected dashed box.