3

QTreeWidget のヘッダーにボタンを配置する方法についてのヒントを教えてください。最小限の例は大歓迎です。

4

2 に答える 2

1
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QHeaderView>
#include <QPushButton>


class Header
    : public QHeaderView
{
public:
    Header(QWidget* parent)
        : QHeaderView(Qt::Horizontal, parent)
        , m_button(new QPushButton("Button", this))
    {
    }

private:
    QPushButton* m_button;
};

class TreeWidget
    : public QTreeWidget
{
    Q_OBJECT
public:
    TreeWidget()
        : QTreeWidget(0)
    {
        QTreeWidgetItem* item0 = new QTreeWidgetItem(QStringList("Item 0"));
        QTreeWidgetItem* item1 = new QTreeWidgetItem(QStringList("Item 1"));
        addTopLevelItem(item0);
        addTopLevelItem(item1);
        createHeader();
    }

private:
    void createHeader()
    {
        m_header = new Header(this);
        setHeader(m_header);
    }

private:
    Header* m_header;

};

int main(int c, char** v)
{
    QApplication a(c, v);

    TreeWidget* tw = new TreeWidget();
    tw->show();

    return a.exec();
}


//QTreeWidget header is an "stand alone" widget - QHeaderView, so you can set the custom implementation of it.
于 2012-04-16T05:52:21.683 に答える