Results 1 to 7 of 7

Thread: Change QTabWidget tabs while resizing

  1. #1
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Change QTabWidget tabs while resizing

    I would like to hide the text and just show the icons on the tabs of my QTabWidget when the user resizes the QTabWidget and hits the minimumSizeHint with the text showing.
    Everything is working fine except when I hide the text I have to release the mouse and click again to continue shrinking the widget, even though I hide the text and call updateGeometry().

    I tried to do this with an event filter. Is there a better way to do this and is this even possible?
    I am using Qt 4.5.2.

    Qt Code:
    1. class TabWidgetEventFilter : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. TabWidgetEventFilter(QObject* parent, QTabWidget* tabWidget)
    7. : QObject(parent)
    8. {
    9. if (!tabWidget)
    10. return;
    11.  
    12. _tabWidget = tabWidget;
    13.  
    14. for (int i = 0; i < _tabWidget->count(); ++i)
    15. _tabNames.append(_tabWidget->tabText(i));
    16.  
    17. _minimumSizeHintWithText = _tabWidget->minimumSizeHint().width();
    18. }
    19.  
    20. protected:
    21. bool eventFilter(QObject* obj, QEvent* event)
    22. {
    23. if (event->type() == QEvent::Resize)
    24. {
    25. QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event);
    26. if (resizeEvent->size().width() <= _minimumSizeHintWithText)
    27. setTextVisible(false);
    28. else
    29. setTextVisible(true);
    30. }
    31.  
    32. return false;
    33. }
    34.  
    35. private:
    36. void setTextVisible(bool visible)
    37. {
    38. for (int i = 0; i < _tabWidget->count(); ++i)
    39. _tabWidget->setTabText(i, visible ? _tabNames.at(i) : QString(""));
    40.  
    41. _tabWidget->updateGeometry();
    42. }
    43.  
    44. QList<QString> _tabNames;
    45. QTabWidget* _tabWidget;
    46. int _minimumSizeHintWithText;
    47. };
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help
    Michael

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change QTabWidget tabs while resizing

    What happens if you don't release the mouse?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change QTabWidget tabs while resizing

    Quote Originally Posted by wysota View Post
    What happens if you don't release the mouse?
    I can't make it smaller than the "old" minimum size hint (the one with text). The text is already hidden and updateGeometry has been called.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change QTabWidget tabs while resizing

    Correct the minimum size hint then so that it doesn't use the text in its calculations. That's the way it should be.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change QTabWidget tabs while resizing

    I just checked the size hint and it seems to return the correct values, so the problem might be that during the resize operation (while the mouse button is pressed) Qt doesn't seem to notice that the size hint has changed and still uses an old value.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change QTabWidget tabs while resizing

    No. Correct minimumSizeHint to ALWAYS return the smaller size, not only when you reach the minimum WHILE resizing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    michael. (17th May 2011)

  8. #7
    Join Date
    Dec 2010
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change QTabWidget tabs while resizing

    Ah of course, I didn't get that.
    Thank you so much.

Similar Threads

  1. QTabWidget with same tabs
    By Djony in forum Qt Programming
    Replies: 20
    Last Post: 24th December 2011, 12:20
  2. Qt Designer How to set a QTabWidget with two rows of tabs?
    By lmfgy123 in forum Qt Tools
    Replies: 1
    Last Post: 17th November 2010, 06:49
  3. Replies: 4
    Last Post: 28th July 2010, 09:57
  4. Qtabwidget - how to add a button to all tabs?
    By creep33 in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2010, 19:05
  5. Switching off all tabs in QTabWidget
    By Gopala Krishna in forum Qt Programming
    Replies: 7
    Last Post: 30th August 2006, 17:10

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.