PDA

View Full Version : QTabWidget fill all parent widget



kaszewczyk
19th February 2010, 07:21
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

high_flyer
19th February 2010, 08:20
Can you show your code?
Did you consider using QSplitter?

kaszewczyk
19th February 2010, 09:00
I can't use splitter becouse i have to use layouts and QSplitter dont suport this.

MainWidget


class Window : public QWidget
{
Q_OBJECT

public:
Window(QWidget *parent = 0);
~Window();

private:
QHBoxLayout* mainLay;
QVBoxLayout* renderLay;
QVBoxLayout* tabLay;
QTabWidget* tabWidget;
RenderArea* topRender;
RenderArea* bottomRender;
PageOne* tabPageOne;
PageTwo* tabPageTwo;

};

RenderArea


class RenderArea : public QWidget
{
Q_OBJECT

public:
RenderArea(QWidget* parent = 0);
virtual ~RenderArea();

protected:
void paintEvent(QPaintEvent* _p);

private:
void paintOscyloCoordSystem(QPainter& __pa, QPen& __pe);
QString scaleNum;
};

MainWidget Constructor:


Window::Window(QWidget *parent)
: QWidget(parent)
{
mainLay = new QHBoxLayout;
renderLay = new QVBoxLayout;
tabLay = new QVBoxLayout;
tabWidget = new QTabWidget(this);
topRender = new RenderArea;
bottomRender = new RenderArea;
tabPageOne = new PageOne(tabWidget);
tabPageTwo = new PageTwo(tabWidget);

renderLay->addWidget(topRender);
renderLay->addWidget(bottomRender);

tabWidget->addTab(tabPageOne, "Strona1");
tabWidget->addTab(tabPageTwo, "Strona2");
tabLay->addWidget(tabWidget);

mainLay->addLayout(tabLay);
mainLay->addLayout(renderLay);
setLayout(mainLay);
}

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?

high_flyer
19th February 2010, 09:09
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..

kaszewczyk
19th February 2010, 09:57
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?

high_flyer
19th February 2010, 10:27
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.