Results 1 to 4 of 4

Thread: setStyleSheet not working

  1. #1
    Join Date
    Dec 2015
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default setStyleSheet not working

    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.

    Qt Code:
    1. #include <QtWebKitWidgets>
    2. #include <QMessageBox>
    3. #include <QUrl>
    4. #include <QMainWindow>
    5. #include <QTabWidget>
    6.  
    7. QWebView *m_mainWebView;
    8.  
    9. QGridLayout *m_tabGridLayout;
    10. QGridLayout *m_mainGridLayout;
    11. QTabWidget *m_tabWidget;
    12. QWidget *m_MainTab;
    13.  
    14. class myMainWindow:public QMainWindow
    15. {
    16. public:
    17. myMainWindow():QMainWindow()
    18. {
    19. QUrl name("www.google.com");
    20. m_tabWidget = new QTabWidget(this);
    21. m_mainGridLayout = new QGridLayout(m_tabWidget);
    22. m_mainGridLayout->setContentsMargins(0, 0, 0, 0);
    23. m_MainTab = new QWidget(m_tabWidget);
    24. m_tabGridLayout = new QGridLayout(m_MainTab);
    25. m_tabGridLayout->setContentsMargins(0, 0, 0, 0);
    26. m_mainWebView = new QWebView(m_MainTab);
    27.  
    28. m_tabGridLayout->addWidget(m_mainWebView, 0, 0, 1, 1);
    29. m_tabWidget->addTab(m_MainTab, QString());
    30. m_tabWidget->setCurrentIndex(0);
    31. m_tabWidget->setTabText(0, "My Customized Tab");
    32. m_tabWidget->setStyleSheet("QTabBar::tab{max-height:100px;max-width:300px;}");
    33.  
    34. setCentralWidget(m_tabWidget);
    35.  
    36. m_mainWebView->setUrl(name);
    37. };
    38. ~myMainWindow(){};
    39. };
    40.  
    41. int main(int argc, char **argv)
    42. {
    43. QApplication app(argc, argv);
    44. myMainWindow *window = new myMainWindow();
    45.  
    46. window->resize(400, 400);
    47. window->setWindowTitle("QTabWidget - Style Testing");
    48. window->show();
    49. return app.exec();
    50. }
    To copy to clipboard, switch view to plain text mode 


    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setStyleSheet not working

    Have you tried
    Qt Code:
    1. m_tabWidget->tabBar()->setFixedSize(...);
    To copy to clipboard, switch view to plain text mode 
    ?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setStyleSheet not working

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setStyleSheet not working

    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,
    _

Similar Threads

  1. QMenu and setStyleSheet
    By BobTheProg in forum Qt Programming
    Replies: 5
    Last Post: 9th July 2010, 14:28
  2. QTableWidget and setStyleSheet()
    By kazek3018 in forum Newbie
    Replies: 3
    Last Post: 30th December 2008, 09:52
  3. Problem to setstylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2008, 07:57
  4. using setStyleSheet
    By Weilor in forum Qt Programming
    Replies: 11
    Last Post: 18th January 2008, 14:41
  5. QApplication::setStyleSheet()
    By Ryhel in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2007, 14:09

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.