Results 1 to 1 of 1

Thread: QT QTabBar. Move close button to right corner QTabBar West possition. Paint event

  1. #1
    Join Date
    Apr 2011
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QT QTabBar. Move close button to right corner QTabBar West possition. Paint event

    Hello Professionals! I have an issue with close button position while using QTabBar.

    Let's look at picture. I would like to move close button to right corner. I try to play with stylesheet, but had fiasko.


    Attachment 7110


    Code:
    Qt Code:
    1. class TestTabBar : public QTabBar
    2. {
    3. public:
    4. explicit TestTabBar(QWidget* parent=0) : QTabBar(parent)
    5. {
    6. }
    7.  
    8. protected:
    9. QSize tabSizeHint(int) const
    10. {
    11. return QSize(120, 20);
    12. }
    13. void paintEvent(QPaintEvent *){
    14. QStylePainter p(this);
    15.  
    16. for (int index = 0; index < count(); index++)
    17. {
    18. QStyleOptionTabV3 tab;
    19. initStyleOption(&tab, index);
    20.  
    21. QIcon tempIcon = tabIcon(index);
    22. QString tempText = this->tabText(index);
    23.  
    24. QRect tabrect = tabRect(index);
    25.  
    26. tab.icon = QIcon();
    27. tab.text = QString();
    28.  
    29. p.drawControl(QStyle::CE_TabBarTab, tab);
    30. tabrect.adjust(0, 3, 0, -3);
    31.  
    32. p.setPen(Qt::black);
    33. p.setFont(QFont("Arial", 7));
    34.  
    35. tempIcon.paint(&p, tabrect, Qt::AlignTop);
    36. p.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText );
    37.  
    38. }
    39. }
    40. };
    41.  
    42. .....
    43.  
    44. WidgetListTabWidget::WidgetListTabWidget(WidgetList* parent)
    45. : QTabWidget(parent)
    46. {
    47. //........
    48. this->setTabBar(new TestTabBar());
    49. this->setTabPosition(QTabWidget::West);
    50. //.........
    51. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. AddTab button in QTabBar
    By ekapek in forum Newbie
    Replies: 2
    Last Post: 3rd July 2010, 19:51
  2. QTabbar style ::scroller to expand the tab scoll button space.
    By AmolShinde_8 in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2010, 15:40
  3. Disable close button on QTabWidget/QTabBar
    By minimoog in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2009, 06:25
  4. QTabBar with optional button to the right of every tab
    By momesana in forum Qt Programming
    Replies: 13
    Last Post: 8th October 2007, 02:32
  5. Replies: 1
    Last Post: 7th July 2007, 10:03

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.