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 <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>
|
2020-03-13 13:32:22 +01:00
|
|
|
#include <QskFunctions.h>
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
#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()
|
|
|
|
{
|
|
|
|
setMargins( QMarginsF( 15, 10, 10, 10 ) );
|
|
|
|
setAlternatingRowColors( true );
|
|
|
|
|
2017-08-23 14:53:29 +02:00
|
|
|
// increasing the padding of each row: usually the job of the skin !
|
2020-12-15 07:21:12 +01:00
|
|
|
setPaddingHint( Cell, 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()
|
|
|
|
{
|
2022-03-25 10:29:12 +01:00
|
|
|
const int count = 10000;
|
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
const QString format( "Row %1: The quick brown fox jumps over the lazy dog" );
|
2022-03-25 10:29:12 +01:00
|
|
|
|
2017-07-21 18:21:34 +02:00
|
|
|
QStringList entries;
|
2022-03-25 10:29:12 +01:00
|
|
|
entries.reserve( count );
|
|
|
|
|
|
|
|
for ( int i = 0; i < count; i++ )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
|
2020-03-13 13:32:22 +01:00
|
|
|
const qreal maxWidth = qskHorizontalAdvance( effectiveFont( Cell ), entries.last() );
|
|
|
|
setColumnWidthHint( 0, maxWidth );
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
append( entries );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
#ifdef ITEM_STATISTICS
|
|
|
|
QskObjectCounter counter( true );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QGuiApplication app( argc, argv );
|
|
|
|
|
|
|
|
SkinnyShortcut::enable( SkinnyShortcut::AllShortcuts );
|
|
|
|
|
|
|
|
QskWindow window;
|
|
|
|
window.setColor( "Silver" );
|
|
|
|
|
|
|
|
window.addItem( new ListBox() );
|
|
|
|
window.resize( 400, 600 );
|
|
|
|
window.show();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|