PDA

View Full Version : setStyleSheet not working



neel5481
18th December 2015, 05:12
Hi All,

I want to set the fixed height and width of QTabWidget's tab but we have observed that setStyleSheet() function is not working in Mac OS Yosemite and it is working perfectly in Linux Ubuntu.



#include <QtWebKitWidgets>
#include <QMessageBox>
#include <QUrl>
#include <QMainWindow>
#include <QTabWidget>

QWebView *m_mainWebView;

QGridLayout *m_tabGridLayout;
QGridLayout *m_mainGridLayout;
QTabWidget *m_tabWidget;
QWidget *m_MainTab;

class myMainWindow:public QMainWindow
{
public:
myMainWindow():QMainWindow()
{
QUrl name("www.google.com");
m_tabWidget = new QTabWidget(this);
m_mainGridLayout = new QGridLayout(m_tabWidget);
m_mainGridLayout->setContentsMargins(0, 0, 0, 0);
m_MainTab = new QWidget(m_tabWidget);
m_tabGridLayout = new QGridLayout(m_MainTab);
m_tabGridLayout->setContentsMargins(0, 0, 0, 0);
m_mainWebView = new QWebView(m_MainTab);

m_tabGridLayout->addWidget(m_mainWebView, 0, 0, 1, 1);
m_tabWidget->addTab(m_MainTab, QString());
m_tabWidget->setCurrentIndex(0);
m_tabWidget->setTabText(0, "My Customized Tab");
m_tabWidget->setStyleSheet("QTabBar::tab{max-height:100px;max-width:300px;}");

setCentralWidget(m_tabWidget);

m_mainWebView->setUrl(name);
};
~myMainWindow(){};
};

int main(int argc, char **argv)
{
QApplication app(argc, argv);
myMainWindow *window = new myMainWindow();

window->resize(400, 400);
window->setWindowTitle("QTabWidget - Style Testing");
window->show();
return app.exec();
}




Above code is not working in Mac OS Yosemite but working in Linux Ubuntu.

Is there any other way to set the fix height and width of QTabWidget's tabBar ?

Thanks in Advance

anda_skoa
18th December 2015, 09:22
Have you tried


m_tabWidget->tabBar()->setFixedSize(...);

?

Cheers,
_

neel5481
18th December 2015, 10:01
Yes , I have tried that it will not work because tabBar() returns the const * so you will not change the height and width.
I have resolved the problem by overriding the QTabBar class and override the tabSizeHint method which will fix the issue.

Thanks for the reply.

anda_skoa
18th December 2015, 10:38
Interesting, the documentation claims that the return value of tabBar() is QTabBar*, without any const: http://doc.qt.io/qt-5/qtabwidget.html#tabBar

Cheers,
_