76 lines
1.8 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the 3-clause BSD License
*****************************************************************************/
#include <SkinnyFont.h>
#include <SkinnyShortcut.h>
2018-08-03 08:15:28 +02:00
#include <QskAspect.h>
2017-07-21 18:21:34 +02:00
#include <QskObjectCounter.h>
#include <QskSimpleListBox.h>
#include <QskWindow.h>
#include <QFontMetricsF>
2018-08-03 08:15:28 +02:00
#include <QGuiApplication>
2017-07-21 18:21:34 +02:00
class ListBox : public QskSimpleListBox
{
2018-08-03 08:15:28 +02:00
public:
2017-07-21 18:21:34 +02:00
ListBox()
{
using namespace QskAspect;
setMargins( QMarginsF( 15, 10, 10, 10 ) );
setAlternatingRowColors( true );
// increasing the padding of each row: usually the job of the skin !
setMarginsHint( Cell | Padding, QMargins( 10, 20, 10, 20 ) );
2017-07-21 18:21:34 +02:00
populate();
setSelectedRow( 5 );
}
2018-08-03 08:15:28 +02:00
private:
2017-07-21 18:21:34 +02:00
void populate()
{
const QString format( "Row %1: The quick brown fox jumps over the lazy dog" );
QStringList entries;
for ( int i = 0; i < 10000; i++ )
{
entries += format.arg( i + 1 );
}
// we know, that the last entry is the longest one and
// can prevent the list box from having to find it out
// the expensive way.
const QFontMetricsF fm( effectiveFont( Cell ) );
setColumnWidthHint( 0, fm.width( entries.last() ) );
append( entries );
}
};
int main( int argc, char* argv[] )
{
#ifdef ITEM_STATISTICS
QskObjectCounter counter( true );
#endif
QGuiApplication app( argc, argv );
SkinnyFont::init( &app );
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
QskWindow window;
window.setColor( "Silver" );
window.addItem( new ListBox() );
window.resize( 400, 600 );
window.show();
return app.exec();
}