PDA

View Full Version : Custom QTabWidget loses capability to re-adjust size



remizero
10th June 2016, 04:19
Hello everyone.

I'm trying to create a custom QTabWidget, that allows me to collapse the page tabs to click or double click on it, provided it is the active tab, because if the tab is another must show me the page that other tab, but only to collapse them show me the tabs or the tab bar.

So far I'm something right, you could say, I think I'm on track, because so far I have managed to "collapse" the pages of the tabs, but I is presenting unexpected behavior, because although, clicking on the active tab me collapses pages and let me click again shows pages after pages show me again, I can not resize the QTabWidget by QSplitter where it is contained.

I've tried various combinations with methods designed for handling QTabWidget size, but without a satisfactory result.

As I could do to release the size restrictions that may apply when making modifications I require for the QSplitter can adjust the size QTabWidget it when you want to move.

Thanks in advance

anda_skoa
11th June 2016, 09:37
It is hard to speculate what the cause could be without having any idea of what you are doing, where the splitter is relative to the tab, etc.
What does "collapse" mean, etc.


Cheers,
_

remizero
11th June 2016, 15:00
Hi again anda_skoa.

Sorry for my poor explanation, I had enough time to add more information about my problem time.

I added three pictures which I hope will serve to explain some idea of ​​what I'm doing.

In the first picture, it is like my application is initially loaded, and even so good, because if I drag the splitter on the left side as well as the other two, each side is scaled to the size desired.

The problem is, when I use the functionality I am trying to implement and is "collapsing" the pages of QTabWidget, because although it does, that is, it "collapses" when I click on the tabs (second image ), and "no-collapse" when again click on them (third image), after this last event, the splitter can not resize the size of the areas it affects, ie, the left side, where It is the QTabWidget and the right side, where the text editor.

In addition to this, I put the initial programming that led to this task.

.h


class ExpandTabBar : public QTabWidget {

Q_OBJECT

public:
explicit ExpandTabBar ( QWidget *parent = 0 );

public slots:
void hideTabPageArea ( int index );

private:
bool tabCollapse;
};


.cpp


void ExpandTabBar::hideTabPageArea ( int index ) {

qDebug () << "El valor de tabCollapse es: " << this->tabCollapse;
if ( this->tabCollapse ) {

switch ( this->tabPosition () ) {

case QTabWidget::West:

//this->resize ( this->tabBar ()->width () * 3, this->height () );
//this->setFixedWidth ( this->tabBar ()->width () * 3 );
this->setMinimumWidth ( this->tabBar ()->width () * 3 );
this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
break;

case QTabWidget::East:

//this->resize ( this->tabBar ()->width () * 3, this->height () );
//this->setFixedWidth ( this->tabBar ()->width () * 3 );
this->setMinimumWidth ( this->tabBar ()->width () * 3 );
this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
break;

case QTabWidget::South:

//this->resize ( this->width (), this->tabBar ()->height () * 3 );
//this->setFixedHeight ( this->tabBar ()->height () * 3 );
this->setMinimumHeight ( this->tabBar ()->height () * 3 );
this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
break;

default:

//this->resize ( this->width (), this->tabBar ()->height () * 3 );
//this->setFixedHeight ( this->tabBar ()->height () * 3 );
this->setMinimumHeight ( this->tabBar ()->height () * 3 );
this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
break;
}
this->tabCollapse = false;

} else {

switch ( this->tabPosition () ) {

case QTabWidget::West:

//this->resize ( this->tabBar ()->width (), this->height () );
//this->setFixedWidth ( this->tabBar ()->width () );
this->setMaximumWidth ( this->tabBar ()->width () );
this->setSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding );
break;

case QTabWidget::East:

//this->resize ( this->tabBar ()->width (), this->height () );
//this->setFixedWidth ( this->tabBar ()->width () );
this->setMaximumWidth ( this->tabBar ()->width () );
this->setSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding );
break;

case QTabWidget::South:

//this->resize ( this->width (), this->tabBar ()->height () );
//this->setFixedHeight ( this->tabBar ()->height () );
this->setMaximumHeight ( this->tabBar ()->height () );
this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Minimum );
break;

default:

//this->resize ( this->width (), this->tabBar ()->height () );
//this->setFixedHeight ( this->tabBar ()->height () );
this->setMaximumHeight ( this->tabBar ()->height () );
this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Minimum );
break;
}
this->tabCollapse = true;
}
qDebug () << "sizeHint is: " << sizeHint ();
qDebug () << "sizePolicy is: " << sizePolicy ();
qDebug () << "size is: " << size ();
}


Do not put the constructor, because it does nothing and explain a little code.

Depending on the position of the lashes, taking the value of the width or height of QTabBar, to know how far I will "collapse" pages QTabWidget and assign the attribute "tabCollapsed" to see if the pages are "collapsed" or not and know which of the two actions run, of course a little rough programming, but as I said, it is only an initial programming.

I hope now be better understood my point;).

Thanks in advance.

anda_skoa
11th June 2016, 15:54
Ah, yes, thanks, that makes it a lot more clear.

I suspect that the problem is setting fixed/maximum sizes, probably with too small values.

However, I think the whole problem can be avoided by not attempting to shrink QTabWidget, but by using QTabBar and a separated QStackedWidget, combined with a suitable layout, maybe wrapped inside a custom widget.

That way collapsing can be implemented by hiding the stacked widget, expanding should be as simple as showing it again.

Roughly something like


class ExpandTabBar : public QWidget
{
// add the API you would need from QTabWidget
// delegate to m_tabBar and m_stackedWidget as neccessary

private:
QTabBar *m_tabBar;
QStackedWidget *m_stackedWidget;
};

void ExpandTabBar::setCollapsed(bool collapsed)
{
m_stackedWidget->setVisible(!collapsed);
}


Cheers,
_

remizero
21st June 2016, 18:19
Hi everyone again.

After researching a lot, and consider and make several tests with the suggestion anda_skoa, I have managed to solve the problem of adjustment that I then had to "crash" area QTabWidget pages.

The answer is somewhat simple and though the programming is inelegant, here is the left in a compressed, if someone has the same problem or something similar.

The solution enables:
1-. "Collapse" the page area of ​​a QTabWidget the minimum level to allow display of the tabs.
2-. "Uncollapse" the page area of ​​restoring the pre QTabWidget "collapse" of the same dimensions.
3-. Resize the tab area via QSplitter.
4-. "Collapse" the page area of ​​a QTabWidget via QSplitter the minimum level to allow display of the tabs.
5-. Even not allow "Uncollapse" via QSplitter.

P.S.1 Something that was me all this research is that when you want to work with changing the size and / or dimensions of a widget, only work with setGeometry, instead of assigning and / or directly modify the values ​​of size, fixedSize and similar, blocking widget functionality as QSplitter convenience to make adjustments when required. Please correct me if I'm wrong.
****
P.S.2 Another interesting thing also I discovered in this search is that it would be much better achieve do this in combination QDockWidget and QStackedWidget, but I failed as assign a custom QTabBar to achieve better handling of the widget to insert and to move them to any DockArea convenience.

Thank you for all anda_skoa.