Results 1 to 2 of 2

Thread: QTabWidget custom draw and empty in designer problems.

  1. #1
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QTabWidget custom draw and empty in designer problems.

    I want to show an empty QTabWidget in the designer but it seems this is not possible, so I have to remove it in code?

    After removing it in code I get an empty tab widget where I would like to display some text in a label in the middle of the tab widget. My question is how can I achieve this?

  2. #2
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget custom draw and empty in designer problems.

    I managed to figure this out, it seemed pretty simple.

    customtab.hpp
    Qt Code:
    1. #ifndef CUSTOMTAB_HPP
    2. #define CUSTOMTAB_HPP
    3.  
    4. #include <QTabWidget>
    5. #include <QLabel>
    6.  
    7. class CustomTab : public QTabWidget
    8. {
    9. public:
    10. CustomTab( QWidget* aParent = 0 );
    11. ~CustomTab();
    12. virtual void tabInserted( int aIndex );
    13. virtual void tabRemoved( int aIndex );
    14. virtual void resizeEvent(QResizeEvent* aEvent );
    15. protected:
    16. void SetLabelPosition();
    17. private:
    18. QLabel* iLabel;
    19. };
    20.  
    21. #endif // CUSTOMTAB_HPP
    To copy to clipboard, switch view to plain text mode 

    customtab.cpp
    Qt Code:
    1. #include "customtab.hpp"
    2. #include <QTabBar>
    3.  
    4. CustomTab::CustomTab( QWidget* aParent )
    5. : QTabWidget( aParent ), iLabel( NULL )
    6. {
    7. iLabel = new QLabel( this );
    8. iLabel->setText( "Double click on a file segment to open it." );
    9. if (count())
    10. {
    11. iLabel->setVisible(false);
    12. }
    13. iLabel->setWordWrap(true);
    14. SetLabelPosition();
    15. }
    16.  
    17. CustomTab::~CustomTab()
    18. {
    19. delete iLabel;
    20. }
    21.  
    22. void CustomTab::tabInserted( int aIndex )
    23. {
    24. if ( count() )
    25. {
    26. iLabel->setVisible(false);
    27. }
    28. }
    29.  
    30. void CustomTab::tabRemoved( int aIndex )
    31. {
    32. if ( !count() )
    33. {
    34. iLabel->setVisible(true);
    35. }
    36. }
    37.  
    38. void CustomTab::resizeEvent( QResizeEvent* aEvent )
    39. {
    40. QTabWidget::resizeEvent( aEvent );
    41. SetLabelPosition();
    42. }
    43.  
    44. void CustomTab::SetLabelPosition()
    45. {
    46. int xpos = width() /2 - iLabel->width() / 2;
    47. int ypos = height() /2 - iLabel->height() /2;
    48. iLabel->move( xpos, ypos );
    49. }
    50.  
    51. // End of file
    To copy to clipboard, switch view to plain text mode 
    Last edited by paulz; 10th December 2009 at 21:52.

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.