Results 1 to 6 of 6

Thread: QTabWidget fill all parent widget

  1. #1
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QTabWidget fill all parent widget

    Hello,
    I want to split main window into 2 parts in first one i plan to put QTabWidget, in second i want to draw some things with QPainter, but i found problem with displaying drawing part becous when i created QTabWidget object it take all window space, could someone help me please.

    Best Ragards
    kaszewczyk

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget fill all parent widget

    Can you show your code?
    Did you consider using QSplitter?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTabWidget fill all parent widget

    I can't use splitter becouse i have to use layouts and QSplitter dont suport this.

    MainWidget
    Qt Code:
    1. class Window : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Window(QWidget *parent = 0);
    7. ~Window();
    8.  
    9. private:
    10. QHBoxLayout* mainLay;
    11. QVBoxLayout* renderLay;
    12. QVBoxLayout* tabLay;
    13. QTabWidget* tabWidget;
    14. RenderArea* topRender;
    15. RenderArea* bottomRender;
    16. PageOne* tabPageOne;
    17. PageTwo* tabPageTwo;
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 
    RenderArea
    Qt Code:
    1. class RenderArea : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. RenderArea(QWidget* parent = 0);
    7. virtual ~RenderArea();
    8.  
    9. protected:
    10. void paintEvent(QPaintEvent* _p);
    11.  
    12. private:
    13. void paintOscyloCoordSystem(QPainter& __pa, QPen& __pe);
    14. QString scaleNum;
    15. };
    To copy to clipboard, switch view to plain text mode 
    MainWidget Constructor:
    Qt Code:
    1. Window::Window(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. mainLay = new QHBoxLayout;
    5. renderLay = new QVBoxLayout;
    6. tabLay = new QVBoxLayout;
    7. tabWidget = new QTabWidget(this);
    8. topRender = new RenderArea;
    9. bottomRender = new RenderArea;
    10. tabPageOne = new PageOne(tabWidget);
    11. tabPageTwo = new PageTwo(tabWidget);
    12.  
    13. renderLay->addWidget(topRender);
    14. renderLay->addWidget(bottomRender);
    15.  
    16. tabWidget->addTab(tabPageOne, "Strona1");
    17. tabWidget->addTab(tabPageTwo, "Strona2");
    18. tabLay->addWidget(tabWidget);
    19.  
    20. mainLay->addLayout(tabLay);
    21. mainLay->addLayout(renderLay);
    22. setLayout(mainLay);
    23. }
    To copy to clipboard, switch view to plain text mode 
    I consider to wrap QTabWidget in class inheriting from QWidget then create object of this class in main window and add to layout but i dont know if it's good idea?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget fill all parent widget

    I can't use splitter becouse i have to use layouts and QSplitter dont suport this.
    Can you explain exactly what you mean by that?
    Because QSplitter does support layouts (it is a QWidget subclass), unless you mean something that I can't make out from the sentence above..
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Oct 2009
    Location
    Poland
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QTabWidget fill all parent widget

    Like u see in code above i have main horizontal layout becouse i want to splitt my application in two parts left and right.
    In left part i want to put QTabWidget where i will have in each page settings for drawing.
    In the right part of window i will have 2 objects of the RenderArea class lay vertically, in them i will do drawing.
    So if its allright to do:
    maiLay->addWidget(QTabWidget)
    mainLay->addLayout(RenderPartLay)
    but i cant do this same with splitter cus this class do not have addLayout method right?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget fill all parent widget

    QSplitter is a QWidget, which has setLayout().
    Only layouts have addLayout().
    You can have a layout on both sides of the QSplitter.
    Read the QSplitter documentation, it is meant exactly for what you want.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 2
    Last Post: 18th November 2010, 22:50
  2. Replies: 7
    Last Post: 14th January 2010, 08:47
  3. Replies: 6
    Last Post: 18th December 2008, 21:16
  4. Maximize a widget (to fill its parent
    By Ohman in forum Qt Programming
    Replies: 5
    Last Post: 13th October 2008, 12:10
  5. Docking a widget to fill a dialog
    By mridey in forum Qt Tools
    Replies: 1
    Last Post: 16th November 2006, 11:45

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.