Development/Tutorials/Programming Tutorial KDE 4/Using QTreeWidget: Difference between revisions
mNo edit summary |
(properly highlight the cpp snippets using <code>; use {{path}} for the filenames) |
||
Line 1: | Line 1: | ||
=Code it= | =Code it= | ||
'''main.cpp''' | '''{{path|main.cpp}}''' | ||
<code cppqt> | |||
#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''' | } | ||
</code> | |||
'''{{path|CMakeLists.txt}}''' | |||
<code> | |||
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} ) | |||
</code> | |||
=Kompile it= | =Kompile it= | ||
Line 47: | Line 51: | ||
=Run it= | =Run it= | ||
./ktreewidget | ./ktreewidget |
Revision as of 11:31, 30 May 2007
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