#include <qapplication.h>
#include <qheader.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qvbox.h>
class Test : public QVBox
{
Q_OBJECT
public:
Test() : idx( 2 )
{
_lv->addColumn( "A" );
_lv->addColumn( "B" );
_lv->addColumn( "C" );
new QListViewItem( _lv, "a1", "b1", "c1" );
new QListViewItem( _lv, "a2", "b2", "c2" );
new QListViewItem( _lv, "a3", "b3", "c3" );
connect( pb, SIGNAL( clicked() ), this, SLOT( switchColumns() ) );
}
private slots:
void switchColumns()
{
_lv->header()->moveSection( 0, idx );
_lv->triggerUpdate();
_lv->header()->update();
idx = 2 - idx;
}
private:
int idx;
};
int main( int argc, char **argv )
{
Test mw;
app.setMainWidget( &mw );
mw.show();
return app.exec();
}
#include "main.moc"
#include <qapplication.h>
#include <qheader.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <qvbox.h>
class Test : public QVBox
{
Q_OBJECT
public:
Test() : idx( 2 )
{
_lv = new QListView( this );
_lv->addColumn( "A" );
_lv->addColumn( "B" );
_lv->addColumn( "C" );
new QListViewItem( _lv, "a1", "b1", "c1" );
new QListViewItem( _lv, "a2", "b2", "c2" );
new QListViewItem( _lv, "a3", "b3", "c3" );
QPushButton *pb = new QPushButton( "Switch", this );
connect( pb, SIGNAL( clicked() ), this, SLOT( switchColumns() ) );
}
private slots:
void switchColumns()
{
_lv->header()->moveSection( 0, idx );
_lv->triggerUpdate();
_lv->header()->update();
idx = 2 - idx;
}
private:
QListView *_lv;
int idx;
};
int main( int argc, char **argv )
{
QApplication app( argc, argv );
Test mw;
app.setMainWidget( &mw );
mw.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks