Development/Tutorials/Programming Tutorial KDE 4/Using QTreeWidget: Difference between revisions

From KDE TechBase
mNo edit summary
m (Text replace - "</code>" to "</syntaxhighlight>")
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Delete}}
=Code it=
=Code it=


'''main.cpp'''
'''{{path|main.cpp}}'''
#include <kapplication.h>
<syntaxhighlight lang="cpp-qt">
#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kaboutdata.h>
#include <QTableWidget>
#include <kcmdlineargs.h>
#include <QTreeWidget>
#include <QTableWidget>
#include <QHeaderView>
#include <QTreeWidget>
#include <QHeaderView>
int main (int argc, char *argv[])
 
{
int main (int argc, char *argv[])
  KAboutData aboutData( "test", "test",
{
      "1.0", "test", KAboutData::License_GPL,
  KAboutData aboutData( "test", "test",
      "(c) 2007" );
      "1.0", "test", KAboutData::License_GPL,
  KCmdLineArgs::init( argc, argv, &aboutData );
      "(c) 2007" );
  KApplication khello;
  KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;
  QTreeWidget* mw=new QTreeWidget(0);
 
  QTreeWidget* mw=new QTreeWidget(0);
  QStringList labels;
 
  mw->setColumnCount(2);
  QStringList labels;
  mw->setEditTriggers(QAbstractItemView::AllEditTriggers);
  mw->setColumnCount(2);
  QTreeWidgetItem* item=new QTreeWidgetItem(0);
  mw->setEditTriggers(QAbstractItemView::AllEditTriggers);
  item->setText(1,"hi");
  QTreeWidgetItem* item=new QTreeWidgetItem(0);
  item->setFlags(Qt::ItemIsEnabled);
  item->setText(1,"hi");
  mw->insertTopLevelItem(0,item);
  item->setFlags(Qt::ItemIsEnabled);
  mw->show();
  mw->insertTopLevelItem(0,item);
  khello.exec();
  mw->show();
}
  khello.exec();
'''CMakeLists.txt'''
}
PROJECT( ktreewidget )
</syntaxhighlight>
FIND_PACKAGE(KDE4 REQUIRED)
'''{{path|CMakeLists.txt}}'''
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . )
<syntaxhighlight lang="text">
PROJECT( ktreewidget )
FIND_PACKAGE(KDE4 REQUIRED)
SET(ktreewidgetsources main.cpp )
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} . )
 
KDE4_ADD_EXECUTABLE(ktreewidget ${ktreewidgetsources} )
 
SET(ktreewidgetsources main.cpp )
TARGET_LINK_LIBRARIES(ktreewidget ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )
 
KDE4_ADD_EXECUTABLE(ktreewidget ${ktreewidgetsources} )
 
TARGET_LINK_LIBRARIES(ktreewidget ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )
</syntaxhighlight>


=Kompile it=
=Kompile it=
Line 47: Line 53:
=Run it=
=Run it=


chmod 777 ktreewidget
  ./ktreewidget
  ./ktreewidget

Revision as of 20:54, 29 June 2011

Warning
This page has been nominated for deletion.

Reason: {{{1}}}

If you disagree with its deletion, remove the template and discuss it on its talk page.


Code it

main.cpp

#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <QTableWidget>
#include <QTreeWidget>
#include <QHeaderView>

int main (int argc, char *argv[])
{
  KAboutData aboutData( "test", "test",
      "1.0", "test", KAboutData::License_GPL,
      "(c) 2007" );
  KCmdLineArgs::init( argc, argv, &aboutData );
  KApplication khello;

  QTreeWidget* mw=new QTreeWidget(0);

  QStringList labels;
  mw->setColumnCount(2);
  mw->setEditTriggers(QAbstractItemView::AllEditTriggers);
  QTreeWidgetItem* item=new QTreeWidgetItem(0);
  item->setText(1,"hi");
  item->setFlags(Qt::ItemIsEnabled);
  mw->insertTopLevelItem(0,item);
  mw->show();
  khello.exec();
}

CMakeLists.txt

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


SET(ktreewidgetsources main.cpp )

KDE4_ADD_EXECUTABLE(ktreewidget ${ktreewidgetsources} )

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

Kompile it

cmake . -DCMAKE_INSTALL_PREFIX=$KDEDIR -DCMAKE_BUILD_TYPE=debugfull && make -j2 VERBOSE=1

Run it

./ktreewidget