PDA

View Full Version : 1 pixel QSplitter



bunjee
22nd August 2008, 00:01
Hey trolls,

I'm using a 1 pixel QSplitter.
The only problem is... since it's a 1 pixel QSplitter it's difficult to drag / drop.
Is there a way to have a 1 pixel Graphical splitter and keeping a 5 pixels draggable area ?

wysota
22nd August 2008, 01:15
You can provide your own handle for the splitter. If you paint only one pixel and keep the remaining four transparent maybe you will obtain your effect.

DIMEDROLL
3rd October 2008, 14:53
How did you create a 1 pixel QSplitter?
I've created QSplitter and added to QListView objects to it. How can I make a separator( between QListView objects) to be 3 pixels width? setHandleWidth() changes only the dragable area...

bunjee
29th January 2009, 13:10
Here is the implementation for a 1 pixel painted + 4 pixels draggable area.

(this code is from QtCreator, licensed in GPL)

Doesn't seem to work on Qt 4.4.3, anyone could confirm this ?


#include "minisplitter.h"
#include "stylehelper.h"

#include <QtGui/QPaintEvent>
#include <QtGui/QPainter>
#include <QtGui/QSplitterHandle>

namespace Core {
namespace Internal {

class MiniSplitterHandle : public QSplitterHandle
{
public:
MiniSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
: QSplitterHandle(orientation, parent)
{
setMask(QRegion(contentsRect()));
setAttribute(Qt::WA_MouseNoMask, true);
}
protected:
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event);
};

} // namespace Internal
} // namespace Core

using namespace Core;
using namespace Core::Internal;

void MiniSplitterHandle::resizeEvent(QResizeEvent *event)
{
if (orientation() == Qt::Horizontal)
setContentsMargins(2, 0, 2, 0);
else
setContentsMargins(0, 2, 0, 2);
setMask(QRegion(contentsRect()));
QSplitterHandle::resizeEvent(event);
}

void MiniSplitterHandle::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.fillRect(event->rect(), StyleHelper::borderColor());
}

QSplitterHandle *MiniSplitter::createHandle()
{
return new MiniSplitterHandle(orientation(), this);
}

MiniSplitter::MiniSplitter(QWidget *parent)
: QSplitter(parent)
{
setHandleWidth(1);
setChildrenCollapsible(false);
setProperty("minisplitter", true);
}

MiniSplitter::MiniSplitter(Qt::Orientation orientation)
: QSplitter(orientation)
{
setHandleWidth(1);
setChildrenCollapsible(false);
setProperty("minisplitter", true);
}

winter
4th March 2009, 13:07
Here is the implementation for a 1 pixel painted + 4 pixels draggable area.

(this code is from QtCreator, licensed in GPL)

Doesn't seem to work on Qt 4.4.3, anyone could confirm this ?


I believe there is a small piece of extra code defined in the manhattanstyle.cpp files



QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
QSize newSize = d->style->sizeFromContents(type, option, size, widget);

if (type == CT_Splitter && widget && widget->property("minisplitter").toBool())
return QSize(1, 1);
else if (type == CT_ComboBox && panelWidget(widget))
newSize += QSize(10, 0);
return newSize;
}

winter
4th March 2009, 13:12
I believe there is a small piece of extra code defined in the manhattanstyle.cpp files



QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
const QSize &size, const QWidget *widget) const
{
QSize newSize = d->style->sizeFromContents(type, option, size, widget);

if (type == CT_Splitter && widget && widget->property("minisplitter").toBool())
return QSize(1, 1);
else if (type == CT_ComboBox && panelWidget(widget))
newSize += QSize(10, 0);
return newSize;
}


I replicated this function without having to create my own style by overriding the sizeHint in the QSplitterHandle subclass:



QSize sizeHint() const
{
return QSize(1, 1);
}