Look at this example:
#include <QApplication>
#include <QListView>
#include <QStringListModel>
#include <QStyledItemDelegate>
#include <QPainter>
class Delegate
: public QStyledItemDelegate
{
public:
Delegate()
{
}
void paint( QPainter * painter, const QStyleOptionViewItem & option,
const QModelIndex & index ) const
{
painter->drawText( option.rect, index.data().toString() );
}
QSize sizeHint( const QStyleOptionViewItem &,
const QModelIndex &) const
{
return QSize( 50, 50 );
}
};
int main( int argc, char ** argv )
{
QApplication app( argc, argv );
QListView view;
view.setFlow( QListView::LeftToRight );
view.setResizeMode( QListView::Adjust );
view.setWrapping( true );
Delegate delegate;
view.setItemDelegate( &delegate );
QStringListModel model;
QStringList items;
for( int i = 0; i < 100; ++i )
items.append( QString::number( i ) );
model.setStringList( items );
view.setModel( &model );
view.show();
return app.exec();
}
On 20.01.2016 17:52, Hualet Wang wrote:
Really ? That’s quite good enough for me if it’s true. Thank you for you
suggestion, I’ll check
it out. :D
在 2016年1月20日,下午10:48,Igor Mironchik <igor.mironc...@gmail.com> 写道:
Hi,
On 20.01.2016 17:09, Hualet Wang wrote:
And one more, what about QTableWidget with icons? And why you decided that
QTableView will not do the trick?
Because I’m not sure if QTableView is capable of re-layouting the items after I
delete one or more cells from it. And that’s the whole point of my question.
Even more: you can use QListView with flow QListView::LeftToRight with
resizeMode QListView::Adjust and proper delegate... And you are happy. Items
will relayout automatically... And will be placed in the table...
And QtMWidgets is for touch-devices...
I’m not targeting touch devices. The application will run on Linux.
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest