Results 1 to 6 of 6

Thread: 1 pixel QSplitter

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default 1 pixel QSplitter

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: 1 pixel QSplitter

    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.

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    Thanks
    3
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: 1 pixel QSplitter

    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...

  4. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: 1 pixel QSplitter

    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 ?

    Qt Code:
    1. #include "minisplitter.h"
    2. #include "stylehelper.h"
    3.  
    4. #include <QtGui/QPaintEvent>
    5. #include <QtGui/QPainter>
    6. #include <QtGui/QSplitterHandle>
    7.  
    8. namespace Core {
    9. namespace Internal {
    10.  
    11. class MiniSplitterHandle : public QSplitterHandle
    12. {
    13. public:
    14. MiniSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
    15. : QSplitterHandle(orientation, parent)
    16. {
    17. setMask(QRegion(contentsRect()));
    18. setAttribute(Qt::WA_MouseNoMask, true);
    19. }
    20. protected:
    21. void resizeEvent(QResizeEvent *event);
    22. void paintEvent(QPaintEvent *event);
    23. };
    24.  
    25. } // namespace Internal
    26. } // namespace Core
    27.  
    28. using namespace Core;
    29. using namespace Core::Internal;
    30.  
    31. void MiniSplitterHandle::resizeEvent(QResizeEvent *event)
    32. {
    33. if (orientation() == Qt::Horizontal)
    34. setContentsMargins(2, 0, 2, 0);
    35. else
    36. setContentsMargins(0, 2, 0, 2);
    37. setMask(QRegion(contentsRect()));
    38. QSplitterHandle::resizeEvent(event);
    39. }
    40.  
    41. void MiniSplitterHandle::paintEvent(QPaintEvent *event)
    42. {
    43. QPainter painter(this);
    44. painter.fillRect(event->rect(), StyleHelper::borderColor());
    45. }
    46.  
    47. QSplitterHandle *MiniSplitter::createHandle()
    48. {
    49. return new MiniSplitterHandle(orientation(), this);
    50. }
    51.  
    52. MiniSplitter::MiniSplitter(QWidget *parent)
    53. : QSplitter(parent)
    54. {
    55. setHandleWidth(1);
    56. setChildrenCollapsible(false);
    57. setProperty("minisplitter", true);
    58. }
    59.  
    60. MiniSplitter::MiniSplitter(Qt::Orientation orientation)
    61. : QSplitter(orientation)
    62. {
    63. setHandleWidth(1);
    64. setChildrenCollapsible(false);
    65. setProperty("minisplitter", true);
    66. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by bunjee; 29th January 2009 at 12:24.

  5. #5
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: 1 pixel QSplitter

    Quote Originally Posted by bunjee View Post
    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

    Qt Code:
    1. QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
    2. const QSize &size, const QWidget *widget) const
    3. {
    4. QSize newSize = d->style->sizeFromContents(type, option, size, widget);
    5.  
    6. if (type == CT_Splitter && widget && widget->property("minisplitter").toBool())
    7. return QSize(1, 1);
    8. else if (type == CT_ComboBox && panelWidget(widget))
    9. newSize += QSize(10, 0);
    10. return newSize;
    11. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: 1 pixel QSplitter

    Quote Originally Posted by winter View Post
    I believe there is a small piece of extra code defined in the manhattanstyle.cpp files

    Qt Code:
    1. QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option,
    2. const QSize &size, const QWidget *widget) const
    3. {
    4. QSize newSize = d->style->sizeFromContents(type, option, size, widget);
    5.  
    6. if (type == CT_Splitter && widget && widget->property("minisplitter").toBool())
    7. return QSize(1, 1);
    8. else if (type == CT_ComboBox && panelWidget(widget))
    9. newSize += QSize(10, 0);
    10. return newSize;
    11. }
    To copy to clipboard, switch view to plain text mode 
    I replicated this function without having to create my own style by overriding the sizeHint in the QSplitterHandle subclass:

    Qt Code:
    1. QSize sizeHint() const
    2. {
    3. return QSize(1, 1);
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to get pixel color from QPainter ??
    By rameshg87 in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2008, 08:58
  2. QSplitter in Designer
    By Boron in forum Qt Tools
    Replies: 2
    Last Post: 21st July 2008, 18:34
  3. how can a pixel be a floating point number
    By babu198649 in forum General Programming
    Replies: 1
    Last Post: 2nd June 2008, 18:05
  4. QPixmap pixel by pixel ?
    By tommy in forum Qt Programming
    Replies: 19
    Last Post: 3rd December 2007, 22:52
  5. How to set Widgets sizes with in QSplitter
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2007, 07:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.