PDA

View Full Version : TabWidget corner button height - is this a bug?



Berryblue031
29th May 2012, 15:35
I have a standard QTabWidget, with a corner widget - the only thing special about the QTabWidget is that I use stylesheets to set the tab height.

Is it possible to get the corner widgets to be the same height as the tabs and still display properly within the tabbar area of the tabwidget?

Here is an example of the problem



#ifndef TABBAR_H
#define TABBAR_H

#include "tabbar.h"
#include <QTabWidget>
#include <QToolButton>
#include <QHBoxLayout>
#include <QLabel>

#include <QtGui/QMainWindow>

class tabbar : public QWidget
{
Q_OBJECT

public:
tabbar(QWidget *parent = 0, Qt::WFlags flags = 0)
: QWidget(parent, flags)
{
QToolButton* leftCornerWidget = new QToolButton();
leftCornerWidget->setText("expanding corner widget");
leftCornerWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);

QToolButton* rightCornerWidget = new QToolButton();
rightCornerWidget->setText("fixed height corner widget");
rightCornerWidget->setFixedHeight(50);

QTabWidget* tabWidget = new QTabWidget(this);
tabWidget->setCornerWidget(leftCornerWidget, Qt::TopLeftCorner);
tabWidget->setCornerWidget(rightCornerWidget, Qt::TopRightCorner);
tabWidget->addTab(new QLabel("How to make a corner widget the same height as the tabs<br>that stays within the bounds of the tabbar?"), QIcon(), "1 tab");
tabWidget->addTab(new QLabel("How to make a corner widget the same height as the tabs<br>that stays within the bounds of the tabbar?"), QIcon(), "2 tab");
tabWidget->setStyleSheet("QTabBar::tab{ height: 50px; }");

QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(tabWidget);

this->setLayout(layout);

resize(300,300);
show();
}
};

#endif // TABBAR_H


I am not sure if there is any other way I could be doing it, or if it is simply a Qt Bug (note on MAC the buttons align to the top properly so this problem is windows / linux)
7762