Results 1 to 13 of 13

Thread: QTabBar??

  1. #1
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTabBar??

    hi all,
    I want to set image on a tab of a tabbar .I want to create tab as the same size of image.
    But size of tab i m creating is bigger than that of image........
    I used the following code
    Qt Code:
    1. QTabBar *tabbar=new QTabWidget(this);
    2. QPixmap image(":/images/abc.png");
    3. QIcon icon(image);
    4. tabbar->addTab(icon," ");
    5. QSize size(image.width(),image.height());
    6. tabbar->setIconSize(size);
    To copy to clipboard, switch view to plain text mode 


    How to do????

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    You don't really describe your problem, but I suspect that you want to stretch your image. This can be done, however, I've run into issues with the QTabBar where I've wanted special looks and I've always ended up subclassing it and reimplementing the painting - just to get control of the size of each tab, etc.

  3. #3
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTabBar??

    thnx for reply,
    I want to create tab of same size of my image..
    how to do that? I m using the code mentioned in previous post.
    but using that code i m not getting the tab size as that of image.
    how to change the size of tab ?

  4. #4
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    In what contents are you using your tabbar? As a part of a QTabWidget, or in another setting.

  5. #5
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTabBar??

    As a part of QTabWidget...

  6. #6
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    I seem to recall that you could set the QTabBar widget for a QTabWidget (cannot seem to locate the method in the 4.5 docs). In that case, you can reimplement the virtual methods at the bottom of this details section: http://doc.trolltech.com/4.5/qtabbar.html#details . Especially: http://doc.trolltech.com/4.5/qtabbar.html#tabSizeHint .

  7. #7
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    Here is the method that I mentioned: http://doc.trolltech.com/4.5/qtabwidget.html#setTabBar . It is protected, so you will have to inherit QTabWidget and call it from your new c'tor.

  8. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    first of all, this cant really do much more than segmentation fault:
    Qt Code:
    1. QTabBar *tabbar=new QTabWidget(this);
    To copy to clipboard, switch view to plain text mode 
    you create pointer to QTabBar and make it pointing to QTabWidget...
    tell me, what this code does:
    Qt Code:
    1. QRect rect = tabbar->tabRect(0);
    To copy to clipboard, switch view to plain text mode 
    ?

    If you want to get the tabbar used in QTabWidget, you have to subclass QTabWidget, because tabBar() and setTabBar() are protected methods.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #9
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTabBar??

    hi,
    this is typing mistake here
    I used
    Qt Code:
    1. QTabBar *tabbar=new QTabBar(this);
    To copy to clipboard, switch view to plain text mode 

    I want to change the size of Tabs in TabBar ...What to do to change it.
    thnx

  10. #10
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    Inherit QTabBar, e.g.

    Qt Code:
    1. class MyTabBar : public QTabBar { ... };
    To copy to clipboard, switch view to plain text mode 

    Re-implement the tabSizeHint function http://doc.trolltech.com/4.5/qtabbar.html#tabSizeHint .

    Inherit QTabWidget:

    Qt Code:
    1. class MyTabWidget : public QTabWidget { ... };
    To copy to clipboard, switch view to plain text mode 

    In your constructor, call setTabbar( ) and make it use MyTabBar.

  11. #11
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTabBar??

    i used tabSizeHint () in MyTabBar class inherited from QTabBar class.
    Qt Code:
    1. class MyTabBar:public QTabBar
    2. {
    3. public:
    4. MyTabBar(QWidget *parent):QTabBar(parent)
    5. {
    6. QIcon callIcon(":/images/a.png");
    7. this->addTab(callIcon," ");
    8. QSize size=this->tabSizeHint(1);
    9. this->setIconSize(size);
    10.  
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 

    but i didn't get wat u mean by reimplementing tabsizehint()??

  12. #12
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    You should not put your code in the QTabBar c'tor. You should re-implement, that is override a virtual method, the size hint function.

    You're then supposed to inherit the QTabWidget from which you use your QTabBar.

    Then, your code uses your tab widget instead of QTabWidget.

  13. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTabBar??

    In other way you have to redefine the tabSizeHint(), because you will not use it, but other objects will, so you have to tell them what the sizeHint is. And you can do it in tabSizeHint(). Something like this:
    Let's say that ClassA uses ClassB and want to know what is the object of ClassB size just to know how to paint it. So the code can be:

    Qt Code:
    1. class ClassB
    2. {
    3. public:
    4. . . .
    5. QSize sizeHint() const { return QSize(100, 100); }
    6. };
    7.  
    8. class ClassA
    9. {
    10. private:
    11. ClassB classb;
    12. public:
    13. void paint() {
    14. QRect rect(QPoint(0, 0), classb.sizeHint());
    15. paintSomethingInRect(something, rect);
    16. }
    17. };
    To copy to clipboard, switch view to plain text mode 
    In your situation ClassB = QTabBar and ClassA = QTabWidget; And as you see QTabWidget and some QTabBar methods want to know how big tabbar is so they ask it through tabSizeHint() method. That's why you have redefined the tabSizeHint().

    P.S. By the way: these things, like "subclassing", "override" and so on are basics of C++ programming, so I think you should equipped yourself with some C++ books/tutorials/websites.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Hiding a tab in QTabBar widget
    By erik in forum Qt Programming
    Replies: 9
    Last Post: 12th February 2017, 12:29
  2. Help on QTabBar colors
    By smacchia in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2012, 16:48
  3. Using QTabBar as QTabWidget replacement
    By invictus in forum Qt Programming
    Replies: 0
    Last Post: 16th August 2008, 01:57
  4. Problems with CSS for QTabBar and QTabWidget
    By visor_ua in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2008, 08:38
  5. problems about QTabBar
    By qtopiahooo in forum Qt Programming
    Replies: 4
    Last Post: 10th October 2006, 10:05

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.