Results 1 to 4 of 4

Thread: QSpitter - prevent resizing

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QSpitter - prevent resizing

    Hi

    How do I lock the position of a QSplitter so that it cannot be moved?

    Thanks

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QSpitter - prevent resizing

    splitters are especially designed to be moved.. if you want fixed position that why not use just a simple layout?

    anyways... try to catch the splitterMoved() signal in a slot and then set back to its original position by calling moveSplitter().

  3. #3
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QSpitter - prevent resizing

    Quote Originally Posted by MrDeath View Post
    splitters are especially designed to be moved.. if you want fixed position that why not use just a simple layout?
    I want the user to be able to move the splitter, but also be able to lock it's position too.
    The widgets on either side are designed to be resizable to suit the needs of the user.

    anyways... try to catch the splitterMoved() signal in a slot and then set back to its original position by calling moveSplitter().
    Nah - doesn't work unfortunately.
    Last edited by jonks; 27th July 2009 at 04:27.

  4. #4
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSpitter - prevent resizing

    One way is to eat the mouse move event of the splitter handle. There are probably more elegant methods though. Here's a little implementation I made:
    Qt Code:
    1. /* Header. */
    2. #include <QSplitterHandle>
    3. class Splitter : public QSplitter
    4. {
    5. public:
    6. Splitter();
    7. void setAllowMove(bool allow);
    8. bool allowMove();
    9.  
    10. protected:
    11. QSplitterHandle *createHandle();
    12.  
    13. private:
    14. bool m_allowMove;
    15. };
    16.  
    17. class SplitterHandle : public QSplitterHandle
    18. {
    19. public:
    20. SplitterHandle(Qt::Orientation orientation, QSplitter* parent);
    21.  
    22. protected:
    23. void mouseMoveEvent ( QMouseEvent * event );
    24. };
    25.  
    26.  
    27. #include <QListView>
    28. #include <QTreeView>
    29. #include <QSplitter>
    30. #include <QDirModel>
    31. #include <QDebug>
    32.  
    33. /* Demonstration. */
    34. MainWindow::MainWindow(QWidget *parent)
    35. : QMainWindow(parent)
    36. {
    37. Splitter *splitter = new Splitter;
    38.  
    39. QListView *lv1 = new QListView;
    40. QListView *lv2 = new QListView;
    41.  
    42. splitter->addWidget(lv1);
    43. splitter->addWidget(lv2);
    44.  
    45. splitter->setAllowMove(false); /* Use as required. */
    46.  
    47. setCentralWidget(splitter);
    48. }
    49.  
    50.  
    51.  
    52. /* Splitter implementation. */
    53. Splitter::Splitter() : QSplitter(), m_allowMove(true) {}
    54.  
    55. bool Splitter::allowMove()
    56. {
    57. return m_allowMove;
    58. }
    59.  
    60. void Splitter::setAllowMove(bool allow)
    61. {
    62. m_allowMove = allow;
    63. }
    64.  
    65. /* SplitterHandle implementation. */
    66. SplitterHandle::SplitterHandle(Qt::Orientation orientation, QSplitter* parent) :
    67. QSplitterHandle(orientation, parent)
    68. {}
    69.  
    70. QSplitterHandle* Splitter::createHandle()
    71. {
    72. return new SplitterHandle(orientation(), this);
    73. }
    74.  
    75. void SplitterHandle::mouseMoveEvent(QMouseEvent * event)
    76. {
    77. if (static_cast<Splitter*>(splitter())->allowMove())
    78. QSplitterHandle::mouseMoveEvent(event);
    79. else
    80. return;
    81. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 14th August 2007, 15:16
  2. QMdiSubWindow resizing in 4.3
    By kalpa in forum Qt Programming
    Replies: 0
    Last Post: 4th June 2007, 13:39
  3. Prevent from resizing a QMainWindow
    By Flier in forum Qt Tools
    Replies: 5
    Last Post: 14th April 2006, 17:11

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.