Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to customize a tabwidget using stylesheet ?

How to customize a tabwidget using stylesheet ?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 8.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Ground
    wrote on last edited by
    #1

    I would like to customize a QTabWidget.
    I have seen a nice example( rounded-border rectangle with a gradient) but it is given in QML....
    http://doc.qt.digia.com/4.7/declarative-ui-components-tabwidget.html

    Any ideas of making that kind of tab using a more simple way, like using stylesheet functions ?

    Thks in advance for any enligtenment :)

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      see "this":http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Ground
        wrote on last edited by
        #3

        Thks! that's exactly what i would like :)
        Do you know how to write external stylesheet like the example above and how to include it in a project ?(i used to use setstylesheet function, but don't know how to use as "external", and i think it will be more simple)

        1 Reply Last reply
        0
        • francescmmF Offline
          francescmmF Offline
          francescmm
          wrote on last edited by
          #4

          You should open a new thread or try to do some Google search. Despite, here is:

          @
          QApplication a(argc, argv);
          QFile file(":/css/StyleSheet.qss");
          if (file.open(QFile::ReadOnly))
          {
          a.setStyleSheet(file.readAll());
          file.close();
          }@

          The StyleSheet.qss is a normal text file but ended with .qss despite .css to mark that is for Qt code. You can put this file wherever you want and include it in a resources (.qrc) file inside the project. With this method you dont need to include the QSS file in your executable folder.

          If you only want to load css styles (in a QSS file or whatever you want) and it is not important for you to include the file in the executable folder, try with this code:

          @
          QApplication a(argc, argv);
          QFile file("css/StyleSheet.qss");
          if (file.open(QFile::ReadOnly))
          {
          a.setStyleSheet(file.readAll());
          file.close();
          }@

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            The easiest way would be to add the css file to your "resource system":http://qt-project.org/doc/qt-4.8/resources.html. But you could also read the file from the file system.

            In Qt (e.g. on startup) read the file and set it either to the QApplication instance or on your MainWindow like this (better on the QApplication so that widgets without parent also get the style set):
            @
            QFile file(":/my-stylesheet.css"); //resource path
            if ( file.open(QFile::ReadOnly) )
            {
            QString css = file.readAll().constData();
            qApp->setStyleSheet( css );
            }
            file.close();
            @

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Ground
              wrote on last edited by
              #6

              Thanks for responses ! i used to did not know about QFile system, i have tried it, but it seems that the changes made in the stylesheet are not synchronized in the execution of my app....
              Maybe i'll post a new thread about that weird thing :)

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                your changes in the stylesheet only take effect once you restart your application...
                unless you use a "QFileSystemWatcher ":http://qt-project.org/doc/qt-4.8/qfilesystemwatcher.html and read and set the stylesheet again on modifications.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Ground
                  wrote on last edited by
                  #8

                  Thks i may need it in my future!

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved