Results 1 to 5 of 5

Thread: Custom QTabWidget loses capability to re-adjust size

  1. #1
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Custom QTabWidget loses capability to re-adjust size

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QTabWidget loses capability to re-adjust size

    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,
    _

  3. #3
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: Custom QTabWidget loses capability to re-adjust size

    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
    Qt Code:
    1. class ExpandTabBar : public QTabWidget {
    2.  
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit ExpandTabBar ( QWidget *parent = 0 );
    7.  
    8. public slots:
    9. void hideTabPageArea ( int index );
    10.  
    11. private:
    12. bool tabCollapse;
    13. };
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. void ExpandTabBar::hideTabPageArea ( int index ) {
    2.  
    3. qDebug () << "El valor de tabCollapse es: " << this->tabCollapse;
    4. if ( this->tabCollapse ) {
    5.  
    6. switch ( this->tabPosition () ) {
    7.  
    8. case QTabWidget::West:
    9.  
    10. //this->resize ( this->tabBar ()->width () * 3, this->height () );
    11. //this->setFixedWidth ( this->tabBar ()->width () * 3 );
    12. this->setMinimumWidth ( this->tabBar ()->width () * 3 );
    13. this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
    14. break;
    15.  
    16. case QTabWidget::East:
    17.  
    18. //this->resize ( this->tabBar ()->width () * 3, this->height () );
    19. //this->setFixedWidth ( this->tabBar ()->width () * 3 );
    20. this->setMinimumWidth ( this->tabBar ()->width () * 3 );
    21. this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
    22. break;
    23.  
    24. case QTabWidget::South:
    25.  
    26. //this->resize ( this->width (), this->tabBar ()->height () * 3 );
    27. //this->setFixedHeight ( this->tabBar ()->height () * 3 );
    28. this->setMinimumHeight ( this->tabBar ()->height () * 3 );
    29. this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
    30. break;
    31.  
    32. default:
    33.  
    34. //this->resize ( this->width (), this->tabBar ()->height () * 3 );
    35. //this->setFixedHeight ( this->tabBar ()->height () * 3 );
    36. this->setMinimumHeight ( this->tabBar ()->height () * 3 );
    37. this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
    38. break;
    39. }
    40. this->tabCollapse = false;
    41.  
    42. } else {
    43.  
    44. switch ( this->tabPosition () ) {
    45.  
    46. case QTabWidget::West:
    47.  
    48. //this->resize ( this->tabBar ()->width (), this->height () );
    49. //this->setFixedWidth ( this->tabBar ()->width () );
    50. this->setMaximumWidth ( this->tabBar ()->width () );
    51. this->setSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding );
    52. break;
    53.  
    54. case QTabWidget::East:
    55.  
    56. //this->resize ( this->tabBar ()->width (), this->height () );
    57. //this->setFixedWidth ( this->tabBar ()->width () );
    58. this->setMaximumWidth ( this->tabBar ()->width () );
    59. this->setSizePolicy ( QSizePolicy::Minimum, QSizePolicy::Expanding );
    60. break;
    61.  
    62. case QTabWidget::South:
    63.  
    64. //this->resize ( this->width (), this->tabBar ()->height () );
    65. //this->setFixedHeight ( this->tabBar ()->height () );
    66. this->setMaximumHeight ( this->tabBar ()->height () );
    67. this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Minimum );
    68. break;
    69.  
    70. default:
    71.  
    72. //this->resize ( this->width (), this->tabBar ()->height () );
    73. //this->setFixedHeight ( this->tabBar ()->height () );
    74. this->setMaximumHeight ( this->tabBar ()->height () );
    75. this->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Minimum );
    76. break;
    77. }
    78. this->tabCollapse = true;
    79. }
    80. qDebug () << "sizeHint is: " << sizeHint ();
    81. qDebug () << "sizePolicy is: " << sizePolicy ();
    82. qDebug () << "size is: " << size ();
    83. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom QTabWidget loses capability to re-adjust size

    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
    Qt Code:
    1. class ExpandTabBar : public QWidget
    2. {
    3. // add the API you would need from QTabWidget
    4. // delegate to m_tabBar and m_stackedWidget as neccessary
    5.  
    6. private:
    7. QTabBar *m_tabBar;
    8. QStackedWidget *m_stackedWidget;
    9. };
    10.  
    11. void ExpandTabBar::setCollapsed(bool collapsed)
    12. {
    13. m_stackedWidget->setVisible(!collapsed);
    14. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    remizero (21st June 2016)

  6. #5
    Join Date
    Jan 2015
    Location
    Barquisimeto, Venezuela
    Posts
    24
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: [SOLVED] Custom QTabWidget loses capability to re-adjust size

    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.
    Attached Files Attached Files
    Last edited by remizero; 21st June 2016 at 20:28.

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2015, 21:58
  2. adjust table size in QDockWidget
    By jackajack01 in forum Qt Programming
    Replies: 0
    Last Post: 13th August 2012, 21:50
  3. I can not adjust the size of a widget to your content.
    By jjcarles in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2010, 23:54
  4. QTabWidget adjust internal Widget to fit full size
    By ^NyAw^ in forum Qt Programming
    Replies: 4
    Last Post: 25th December 2009, 02:20
  5. adjust font size to QLabel-size
    By hunsrus in forum Qt Programming
    Replies: 0
    Last Post: 9th July 2008, 15:33

Tags for this Thread

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.