#ifndef TRASH2_H
#define TRASH2_H
#include <QtGui/QMainWindow>
#include <QToolButton>
#include <QStringList>
#include "ui_trash2.h"
{
Q_OBJECT
public:
trash2
(QWidget *parent
= 0, Qt
::WFlags flags
= 0) {
ui.setupUi(this);
item = addTopLevelItem( 0 );
addSubLevelItem( item, 0 );
addSubLevelItem( item, 1 );
addSubLevelItem( item, 2 );
}
~trash2()
{
}
{
ui.treeWidget->addTopLevelItem( item );
return item;
}
{
button
->setText
( QString("button%1").
arg(i
) );
button->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
button->setAutoRaise( true );
button->setChecked( false );
connect( button, SIGNAL( pressed() ), this, SLOT( buttonPressed() ) );
parentItem->addChild( item );
vmi[button] = item;
ui.treeWidget->setItemWidget( item, 0, button );
}
public slots:
void buttonPressed()
{
QToolButton* button
= dynamic_cast<QToolButton
* >
( sender
() );
if ( button )
{
vmi.remove( button );
button->disconnect();
button->deleteLater();
if ( parent )
{
parent->removeChild( item );
}
delete item;
}
}
private:
Ui::trash2Class ui;
};
#endif // TRASH2_H
#ifndef TRASH2_H
#define TRASH2_H
#include <QtGui/QMainWindow>
#include <QToolButton>
#include <QStringList>
#include "ui_trash2.h"
class trash2 : public QMainWindow
{
Q_OBJECT
public:
trash2(QWidget *parent = 0, Qt::WFlags flags = 0)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
QTreeWidgetItem* item = 0;
item = addTopLevelItem( 0 );
addSubLevelItem( item, 0 );
addSubLevelItem( item, 1 );
addSubLevelItem( item, 2 );
}
~trash2()
{
}
QTreeWidgetItem* addTopLevelItem(int i)
{
QTreeWidgetItem* item = 0;
QStringList list;
list << QString("Top%1").arg(i);
item = new QTreeWidgetItem( list );
ui.treeWidget->addTopLevelItem( item );
return item;
}
void addSubLevelItem(QTreeWidgetItem* parentItem, int i)
{
QTreeWidgetItem* item = 0;
QToolButton* button = 0;
QStringList list;
item = new QTreeWidgetItem( parentItem );
button = new QToolButton( ui.treeWidget );
button->setText( QString("button%1").arg(i) );
button->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
button->setAutoRaise( true );
button->setChecked( false );
connect( button, SIGNAL( pressed() ), this, SLOT( buttonPressed() ) );
parentItem->addChild( item );
vmi[button] = item;
ui.treeWidget->setItemWidget( item, 0, button );
}
public slots:
void buttonPressed()
{
QToolButton* button = dynamic_cast<QToolButton* >( sender() );
if ( button )
{
QTreeWidgetItem* item = vmi[button];
vmi.remove( button );
button->disconnect();
button->deleteLater();
QTreeWidgetItem* parent = item->parent();
if ( parent )
{
parent->removeChild( item );
}
delete item;
}
}
private:
Ui::trash2Class ui;
QMap<QToolButton* , QTreeWidgetItem* > vmi;
};
#endif // TRASH2_H
To copy to clipboard, switch view to plain text mode
Bookmarks