forked from qt-creator/qt-creator
Utils::TreeWidgetColumStretcher: Generalize to support all QHeaderViews
I need this for a QTableView. Change-Id: I07f4c6561abc2c62ce19a21a2233c65210329ef6 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "treewidgetcolumnstretcher.h"
|
#include "headerviewstretcher.h"
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QHideEvent>
|
#include <QHideEvent>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
@@ -35,24 +35,24 @@
|
|||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class Utils::TreeWidgetColumnStretcher
|
\class Utils::HeaderViewStretcher
|
||||||
|
|
||||||
\brief The class fixes QTreeWidget to resize all columns to contents, except one
|
\brief The class fixes QHeaderView to resize all columns to contents, except one
|
||||||
stretching column.
|
stretching column.
|
||||||
|
|
||||||
As opposed to standard QTreeWidget, all columns are
|
As opposed to standard QTreeWidget, all columns are
|
||||||
still interactively resizable.
|
still interactively resizable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TreeWidgetColumnStretcher::TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch)
|
HeaderViewStretcher::HeaderViewStretcher(QHeaderView *headerView, int columnToStretch)
|
||||||
: QObject(treeWidget->header()), m_columnToStretch(columnToStretch)
|
: QObject(headerView), m_columnToStretch(columnToStretch)
|
||||||
{
|
{
|
||||||
parent()->installEventFilter(this);
|
headerView->installEventFilter(this);
|
||||||
QHideEvent fake;
|
QHideEvent fake;
|
||||||
TreeWidgetColumnStretcher::eventFilter(parent(), &fake);
|
HeaderViewStretcher::eventFilter(headerView, &fake);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TreeWidgetColumnStretcher::eventFilter(QObject *obj, QEvent *ev)
|
bool HeaderViewStretcher::eventFilter(QObject *obj, QEvent *ev)
|
||||||
{
|
{
|
||||||
if (obj == parent()) {
|
if (obj == parent()) {
|
||||||
if (ev->type() == QEvent::Show) {
|
if (ev->type() == QEvent::Show) {
|
||||||
@@ -27,27 +27,27 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef TREEWIDGETCOLUMNSTRETCHER_H
|
#ifndef HEADERVIEWSTRETCHER_H
|
||||||
#define TREEWIDGETCOLUMNSTRETCHER_H
|
#define HEADERVIEWSTRETCHER_H
|
||||||
|
|
||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTreeWidget;
|
class QHeaderView;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT TreeWidgetColumnStretcher : public QObject
|
class QTCREATOR_UTILS_EXPORT HeaderViewStretcher : public QObject
|
||||||
{
|
{
|
||||||
const int m_columnToStretch;
|
const int m_columnToStretch;
|
||||||
public:
|
public:
|
||||||
explicit TreeWidgetColumnStretcher(QTreeWidget *treeWidget, int columnToStretch);
|
explicit HeaderViewStretcher(QHeaderView *headerView, int columnToStretch);
|
||||||
|
|
||||||
virtual bool eventFilter(QObject *obj, QEvent *ev);
|
virtual bool eventFilter(QObject *obj, QEvent *ev);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
#endif // TREEWIDGETCOLUMNSTRETCHER_H
|
#endif // HEADERVIEWSTRETCHER_H
|
||||||
@@ -45,7 +45,7 @@ SOURCES += $$PWD/environment.cpp \
|
|||||||
$$PWD/consoleprocess.cpp \
|
$$PWD/consoleprocess.cpp \
|
||||||
$$PWD/uncommentselection.cpp \
|
$$PWD/uncommentselection.cpp \
|
||||||
$$PWD/parameteraction.cpp \
|
$$PWD/parameteraction.cpp \
|
||||||
$$PWD/treewidgetcolumnstretcher.cpp \
|
$$PWD/headerviewstretcher.cpp \
|
||||||
$$PWD/checkablemessagebox.cpp \
|
$$PWD/checkablemessagebox.cpp \
|
||||||
$$PWD/styledbar.cpp \
|
$$PWD/styledbar.cpp \
|
||||||
$$PWD/stylehelper.cpp \
|
$$PWD/stylehelper.cpp \
|
||||||
@@ -129,7 +129,7 @@ HEADERS += \
|
|||||||
$$PWD/textfileformat.h \
|
$$PWD/textfileformat.h \
|
||||||
$$PWD/uncommentselection.h \
|
$$PWD/uncommentselection.h \
|
||||||
$$PWD/parameteraction.h \
|
$$PWD/parameteraction.h \
|
||||||
$$PWD/treewidgetcolumnstretcher.h \
|
$$PWD/headerviewstretcher.h \
|
||||||
$$PWD/checkablemessagebox.h \
|
$$PWD/checkablemessagebox.h \
|
||||||
$$PWD/qtcassert.h \
|
$$PWD/qtcassert.h \
|
||||||
$$PWD/styledbar.h \
|
$$PWD/styledbar.h \
|
||||||
|
|||||||
@@ -161,8 +161,8 @@ QtcLibrary {
|
|||||||
"tcpportsgatherer.h",
|
"tcpportsgatherer.h",
|
||||||
"textfileformat.cpp",
|
"textfileformat.cpp",
|
||||||
"textfileformat.h",
|
"textfileformat.h",
|
||||||
"treewidgetcolumnstretcher.cpp",
|
"headerviewstretcher.cpp",
|
||||||
"treewidgetcolumnstretcher.h",
|
"headerviewstretcher.h",
|
||||||
"uncommentselection.cpp",
|
"uncommentselection.cpp",
|
||||||
"uncommentselection.h",
|
"uncommentselection.h",
|
||||||
"unixutils.cpp",
|
"unixutils.cpp",
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/treewidgetcolumnstretcher.h>
|
#include <utils/headerviewstretcher.h>
|
||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
@@ -90,7 +90,7 @@ QWidget *CommandMappings::createPage(QWidget *parent)
|
|||||||
connect(m_page->targetEdit, SIGNAL(textChanged(QString)),
|
connect(m_page->targetEdit, SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(targetIdentifierChanged()));
|
this, SLOT(targetIdentifierChanged()));
|
||||||
|
|
||||||
new Utils::TreeWidgetColumnStretcher(m_page->commandList, 1);
|
new Utils::HeaderViewStretcher(m_page->commandList->header(), 1);
|
||||||
|
|
||||||
commandChanged(0);
|
commandChanged(0);
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,6 @@
|
|||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/savedaction.h>
|
#include <utils/savedaction.h>
|
||||||
#include <utils/treewidgetcolumnstretcher.h>
|
|
||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
|
|
||||||
#include <cpptools/cpptoolsconstants.h>
|
#include <cpptools/cpptoolsconstants.h>
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <utils/treewidgetcolumnstretcher.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/buildablehelperlibrary.h>
|
#include <utils/buildablehelperlibrary.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user