Results 1 to 11 of 11

Thread: QTabWidget transparent background problem

  1. #1
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTabWidget transparent background problem

    Dear Qt experts,

    I am having a problem in setting the background color of a QTabWidget to transparent.
    What I would like to achieve is to have an image in the mainWindow background that shows through all the small windows on top of it.
    I managed to do that with QTableView and QStackedWidget by setting the styelSheet.
    For the QTabWidget instead there seems to be some additional default background which is set to white and that I cannot manage to make transparent.
    Here are the settings I have tried in the styleSheet:

    QString style("");
    style += (QString::fromUtf8("QTableView, "));
    style += QString::fromUtf8("QTabBar::tab, ");
    style += QString::fromUtf8("QTabWidget, ");
    style += QString::fromUtf8("QTextEdit, ");
    style += QString::fromUtf8("QListView, ");
    style += QString::fromUtf8("QWidget, ");
    style += QString::fromUtf8("QStackedWidget, ");
    style += QString::fromUtf8("QStackedLayout, ");
    style += QString::fromUtf8("QRect, ");
    style += QString::fromUtf8("QTableCornerButton, ");
    style += QString::fromUtf8("QAbstractButton, ");
    style += QString::fromUtf8("QTabWidget:ane, ");
    style += QString::fromUtf8("QTabWidget::left-corner, ");
    style += QString::fromUtf8("QTabWidget::right-corner, ");
    style += QString::fromUtf8("QAbstractScrollArea, ");
    style += QString::fromUtf8("QCheckBox, ");
    style += QString::fromUtf8("QComboBox, ");
    style += QString::fromUtf8("QSpinBox, ");
    style += QString::fromUtf8("QFrame, ");
    style += QString::fromUtf8("QGroupBox, ");
    style += QString::fromUtf8("QHeaderView, ");
    style += QString::fromUtf8("QLineEdit, ");
    style += QString::fromUtf8("QMenu, ");
    style += QString::fromUtf8("QMenuBar, ");
    style += QString::fromUtf8("QProgressBar, ");
    style += QString::fromUtf8("QPushButton, ");
    style += QString::fromUtf8("QRadioButton, ");
    style += QString::fromUtf8("QScrollBar, ");
    style += QString::fromUtf8("QSizeGrip, ");
    style += QString::fromUtf8("QSlider, ");
    style += QString::fromUtf8("QSplitter, ");
    style += QString::fromUtf8("QStatusBar, ");
    style += QString::fromUtf8("QTabWidget, ");
    style += QString::fromUtf8("QTabBar, ");
    style += QString::fromUtf8("QTableWidget, ");
    style += QString::fromUtf8("QToolBar, ");
    style += QString::fromUtf8("QToolBox, ");
    style += QString::fromUtf8("QToolButton, ");
    style += QString::fromUtf8("QToolTip, ");
    style += QString::fromUtf8("QTreeView ");
    style += QString::fromUtf8("{");
    style += QString::fromUtf8("background-color: rgba(255, 255, 55, 55);");
    style += QString::fromUtf8("alternate-background-color: rgba(255, 255, 55, 55);");
    style += QString::fromUtf8("selection-color: rgba(255, 255, 55, 55);");
    style += QString::fromUtf8("selection-background-color: rgba(255, 255, 55, 55);");
    style += QString::fromUtf8("background-origin: content;");
    style += QString::fromUtf8("background-clip: margin;");
    style += QString::fromUtf8("}");

    ui->tabWidget->setStyleSheet(style);

    With these settings (that are overly exagerated) I get the transparent background for the tab bar and I also get a yellow (255, 255, 55) color over a white background on the main QTabWidget area.
    The very same settings work on a QTableView or QStakcedWidget.

    I also tried to use:
    QPalette p = ui->tabWidget->palette();
    p.setBrush( QPalette::Base, QBrush( QColor::fromRgbF(255, 255, 55, 55) ) );
    ui->tabWidget->setPalette(p);
    which I found on another thread of this forum, but it does not change anything.

    I should add that I am testing this on windows xp using Qt 4.5 in QtCreator 1.0.

    Any help would be greatly appreciated!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget transparent background problem

    which I found on another thread of this forum, but it does not change anything.
    I remember in some previous thread it was mention those settings dont work with windows style. Try running you application with some different style, plastique.
    your_application.exe -style plastique

  3. #3
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget transparent background problem

    Yes that did it!
    So the windows style is bugged.

    Do you know if I can set the plastique style directly in the application? Or maybe even in QtDesigner?
    Edit: I found it:
    QStyleFactory styleFactory;
    qApplication.setStyle(styleFactory.create("plastiq ue"));

    This thing has been a pain for a week, thank you so much!!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTabWidget transparent background problem

    Quote Originally Posted by destroyar0 View Post
    QStyleFactory styleFactory;
    qApplication.setStyle(styleFactory.create("plastiq ue"));
    better use simply in your main function:

    Qt Code:
    1. ...
    2. QApplication::setStyle(new QPlastiqueStyle); // or QCleanlooksStyle, or...
    3. QApplication a(argc, argv);
    4. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 20th June 2009 at 11:56. Reason: updated contents: changed order of the code...

  5. #5
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget transparent background problem

    Indeed this is more compact, I moved to this approach.

    Now I have one additional problem that seems really strange to me. When I run the application in my computer, where I have qt installed, it works drawing the background image in the mainWindow and the transparent windows on top of it.

    I then create a directory including the QtCore4.dll, QtGui4.dll and the executable and try it on another computer with windows xp. Everything works but the background image is not displayed.
    The very same directory works with the background image dispalyed on my computer though.

    I have checked for additional dependencies using the Dependency Walker and it only needs those two dlls from Qt.

    Do you have any idea of what could be the problem?

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTabWidget transparent background problem

    What format is your image, you need to distribute the needed image plugins with the application. (On your computer it works because you have set the PATH to your dev-env and so the plugins are found. Dependency Walker doesn't show you that...)

  7. #7
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget transparent background problem

    This is something I did not really know
    What I do is:
    Qt Code:
    1. QString backgroundImage = QString::fromUtf8("QMainWindow {background-image: url(");
    2. if( !imageName.isEmpty() ) {
    3. backgroundImage += imageName;
    4. }
    5. backgroundImage += QString::fromUtf8("); background-clip: content;}");
    6. setStyleSheet(backgroundImage);
    To copy to clipboard, switch view to plain text mode 
    where imageName is a QString containing the name read from file so that it can be customized.
    So far I have only tested it with jpg.
    Where can I find documentation on the image plugins and how do I find out the files I need to include?

    Thanks!

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTabWidget transparent background problem

    Are you developing or windows or linux? And are you sure your image path is correct on the other machine? For that images I prefer it to be bundled with the executable. You may wanna have a look at the Qt Resource System, which allows you to store images inside your application.

  9. #9
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget transparent background problem

    I am developing for windows xp and the image path is relative.
    I do not want to store the image in the application because I want the user to be able to change it.
    I have a configuration file from which I read the image name with this format:
    DefaultBackgroundImage: images/DefaultBackground.jpg

    where images is a directory in the same dir of the executable.

    As you pointed out this should depend on the PATH set by the qtCreator, since when I uninstalled the qt sdk, the background image was not showing anymore even on my computer.

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTabWidget transparent background problem

    Quote Originally Posted by destroyar0 View Post
    As you pointed out this should depend on the PATH set by the qtCreator, since when I uninstalled the qt sdk, the background image was not showing anymore even on my computer.
    No I was mentioned the PATH of your operation system which points the the Qt libraries and plugins. And your description points in the direction that you need to deploy the required image plugins with your application. Since the png format in implemented (<- don't know the right word for that) in the QtGui.dll test if the image is displayed right on both computers if you transform it to PNG. If so, you definitely know that some plugin (= the JPEG plugin) is missing.

  11. #11
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget transparent background problem

    Hello,

    I am sorry I forgot to post the solution to this problem.

    In the end all I needed to do was copying the dir "imageformats" in the dir containing the executable.
    Of course the one provided with Qt contains more than I need, so I just removed all the unnecessary files.
    This way it displays correctly the background image also on other computers.

    I found a useful description in:http://doc.trolltech.com/qq/qq10-win...eployment.html under plugins.

    Thank you very much Lykurg for all your help!

Similar Threads

  1. QTabWidget problem
    By alan lenton in forum Qt Programming
    Replies: 5
    Last Post: 25th July 2016, 16:16
  2. transparent background
    By fruzzo in forum Qt Programming
    Replies: 13
    Last Post: 18th March 2008, 14:42
  3. StyleSheet Problem with QTabWidget
    By December in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 22:16
  4. QTabWidget Parenting Problem
    By mclark in forum Newbie
    Replies: 4
    Last Post: 18th January 2007, 15:20
  5. QTabWidget - problem with resizing
    By moowy in forum Qt Programming
    Replies: 5
    Last Post: 14th September 2006, 14:06

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.