Difference between revisions of "Tutorials/C Programming Tutorial/How to use a QTreeWidget"

From ThorstensHome
Jump to: navigation, search
 
m (1 revision(s))

Revision as of 10:09, 18 October 2008

This is a very minimalistic QTreeWidget coding demonstration - you can use it to learn, and as a template.

main.cpp

#include <QTreeWidget>
#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <KMainWindow>

int main (int argc, char *argv[])
{
  const QByteArray& ba=QByteArray("test");
  const KLocalizedString name=ki18n("myName");
  KAboutData aboutData( ba, ba, name, ba, name);
  KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;
  KMainWindow* mainwindow=new KMainWindow();
  QWidget* mywidget=new QWidget();
  QTreeWidget* qw=new QTreeWidget(mywidget);
  qw->setColumnCount(3);
  QStringList columns;
  columns << "first column" << "second column" << "third column";
  QTreeWidgetItem* item=new QTreeWidgetItem(qw,columns);
  qw->addTopLevelItem(item);
  mainwindow->setCentralWidget(mywidget);
  mainwindow->show();
  return khello.exec();
}

CMakeLists.txt

PROJECT( tutorial )
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . )


SET(tutorialSources main.cpp )

KDE4_ADD_EXECUTABLE(tutorial ${tutorialSources} )

TARGET_LINK_LIBRARIES(tutorial ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )

To compile, link and run this program, use:

cmake . && make && ./tutorial