Thanks wysota, I'll try your suggestions.
Thanks wysota, I'll try your suggestions.
wysota, I though I would try what appeared to be the easiest possibilities first.
The following displayed the image under the horizontal header but not on the white table surface (I could see it extend to the end of the table where the header was not drawn). Is there something I'm missing here?You can set a background image using QWidget::setPalette() and setting a pixmap as a brush for the Base role.
Qt Code:
m_pTable->setHorizontalHeaderLabels( sLabels ); m_pTable->setPalette( palette );To copy to clipboard, switch view to plain text modeI used the following code to try to implement this but I feel I'm missing the point you were making. It shows nothing on the table surface. Is this remotely what you were suggesting?Or you can even put a QLabel on the table (as the child of the viewport).
I'll now look at the event filter suggestion you made, although that looks more complicated than I wanted to try.Qt Code:
m_pTable->setHorizontalHeaderLabels( sLabels ); vLayout->addWidget( &lbl ); viewport->setLayout( vLayout );To copy to clipboard, switch view to plain text mode
Thanks for you help.
The palette has to be set on the viewport not on the widget itself.
Setting the palette on the viewport of the table displays no hint of the image. Does the following code express what you are referring to?
Qt Code:
m_pTable->setHorizontalHeaderLabels( sLabels ); //m_pTable->setPalette( palette ); m_pTable->viewport()->setPalette( palette );To copy to clipboard, switch view to plain text mode
No. You have to use QPalette::Base instead of QPalette::Window.
Thanks so much for your help. QPalette::Base is correct, but not when setting the palette on the viewport. QPalette::Base must be used when setting the palette on the table. Once I did that the image displays as we expected!
Qt Code:
m_pTable->setHorizontalHeaderLabels( sLabels ); m_pTable->setPalette( palette );To copy to clipboard, switch view to plain text mode
One last question. I will need to display a normal background when a table row is added. Is there an efficient way to do this other than either saving the original QPalette and repeating the code with an empty QBrush or creating a white background image to use?
You should be able to query the style() for a default palette.
mclark (1st February 2008)
Hi, sorry to bring this article up, but I really need some help.
Here's my code:
Qt Code:
ui->tableWidget->setPalette(palette); ui->tableWidget->show();To copy to clipboard, switch view to plain text mode
What did I do wrong, that only the background behind cells gets colored?
Cells are still white.
I'm using designer.
Here's image of the problem.
problem.jpg
Is there an easy way to make cells transparent or somehow use the image as background?
Any help would be appreciated.
You're problem is different than the one I started this thread about. I had an empty table - no rows, no columns and wanted an image to display. You need transparent cells so the background image can show through.
While I don't know how to do this, I would start by giving the cells no brush.
If that didn't work I would look at setting the opacity of the brush (see QBrush documentation) or maybe this could be handled with a stylesheet.Qt Code:
To copy to clipboard, switch view to plain text mode
If you get nowhere with these suggestions, start a new thread. There are some very bright developers on this forum and someone must know the answer to this problem.
I know this is an old thread but i have the same problem
i have written this:
Qt Code:
playlistTable.setPalette(palette);To copy to clipboard, switch view to plain text mode
and it doesn't work
PS: using QtJambi
Bookmarks