PDA

View Full Version : Are the QTabWidget and QTableView drawn based on the top-level window?



dotboy
5th July 2009, 05:37
Here is my question:
1. A transparent window(with Qt::Window Flag) has 2 sub-child-widget layouted by QVBoxLayout, and the buttom one has another sub-child-widget QTabWidget which then I put some QTableViews on. ----the structre
2. Back to the top-level window, if I invoke blew:
toplevelWindow->setAutoFillBackground(false); it'll show the window like:
2.jpg(the first image) well transparency, but the Table View was not correct
3. toplevelWindow->setAutoFillBackground(true); it'll show the windowas:
1.jpg(the second image) the Background was painted black by system
I just want the top-level window to be transparent but not child widget...
PlateForm: Windows +qt 4.5.2

dotboy
5th July 2009, 11:51
Is there anyone who can help me with this problem...thx...

wysota
5th July 2009, 11:56
Could you maybe explain again in other words what you mean? I don't see a question in your question :)

dotboy
5th July 2009, 16:16
Could you maybe explain again in other words what you mean? I don't see a question in your question :)

ok, if I set the attribute of the top level widget with Qt::WA_TranslucentBackground but not set the autoFillBackground, then the child widget (like QTabWidget and QTableWidget) will not show as I want;
And if I set them both (WA_TranslucentBackground and autoFillBackground), the child widget act as what I expect but the top level widget was not transparent...

Do you know what I mean now? Thank you for your reply....

wysota
5th July 2009, 17:00
So you want a translucent parent with an opaque child, correct? I don't see why it shouldn't work, so we can try pinpointing the problem. Could you prepare a minimal compilable example reproducing the problem?

dotboy
6th July 2009, 02:45
Did you see the jpgs that I uploaded before?
I've already test the code for many times and the different between them is that if I set the transparency attribute of the top-level window. If it does then part of the child widgets(e.g through the QTabWidget's tab part we can see the desktop ) will show unexpected results.
Hers is my code:

DDialog::DDialog(QWidget* parent)
:QWidget(parent, Qt::FramelessWindowHint | Qt::Dialog)
{
//this->setAutoFillBackground(true); //if it is set the top-level window was not transparent
//if not, the child widget was not show correctly
this->setAttribute(Qt::WA_TranslucentBackground);
this->move(50, 50);
this->resize(420, 430);
this->Initialize();
}


void DDialog::Initialize()
{
QVBoxLayout* layout = new QVBoxLayout(this);
this->setLayout(layout);
layout->setMargin(0);
layout->setSpacing(0);
//TitleBar ZONE
this->m_titleBar = new DTitleBar(this);
layout->addWidget(m_titleBar);

this->m_mainWidget = new QWidget();
layout->addWidget(m_mainWidget);
m_mainWidget->setAutoFillBackground(true);

QStatusBar* statusBar = new QStatusBar();
layout->addWidget(statusBar);
statusBar->setAutoFillBackground(true);
QVBoxLayout* centerLayout = new QVBoxLayout();
this->m_mainWidget->setLayout(centerLayout);

//TabWidget ZONE
this->m_tabWidget = new QTabWidget();
this->m_tabWidget->setAttribute(Qt::WA_OpaquePaintEvent);
centerLayout->addWidget(this->m_tabWidget);
centerLayout->setMargin(10);
this->m_tabWidget->setAutoFillBackground(true);

m_tabWidget->setGeometry(QRect(20, 20, 381, 361));
this->m_tabWidget->setTabPosition(QTabWidget::North);
this->m_tabWidget->setTabShape(QTabWidget::Rounded);
this->m_tabWidget->setElideMode(Qt::ElideMiddle);

//TableView ZONE
this->m_bmpTableHView = new QTableView();
this->m_bmpTableIView = new QTableView();
this->m_bmpTableHView->setAutoFillBackground(true);
this->m_bmpTableIView->setAutoFillBackground(true);
this->m_bmpTableHView->setGeometry(QRect(-10, -10, 391, 351));
this->m_bmpTableHView->setFrameShadow(QFrame::Sunken);
this->m_tabWidget->addTab(this->m_bmpTableHView, "BitMapHead");
this->m_tabWidget->addTab(this->m_bmpTableIView, "BitMapInfoHead");

//QStandardItemModel ZONE
this->m_tableHModel = new QStandardItemModel(4, 3, this);
this->m_tableHModel->setHeaderData(0, Qt::Horizontal, tr("Name"));
this->m_tableHModel->setHeaderData(1, Qt::Horizontal, tr("Bytes"));
this->m_tableHModel->setHeaderData(2, Qt::Horizontal, tr("Value"));
this->m_bmpTableHView->setModel(this->m_tableHModel);

this->m_tableIModel = new QStandardItemModel(4, 3, this);
this->m_tableIModel->setHeaderData(0, Qt::Horizontal, tr("Name"));
this->m_tableIModel->setHeaderData(1, Qt::Horizontal, tr("Bytes"));
this->m_tableIModel->setHeaderData(2, Qt::Horizontal, tr("Value"));
this->m_bmpTableIView->setModel(this->m_tableIModel);

//BUTTON ZONE
QHBoxLayout* buttomLayout = new QHBoxLayout();
centerLayout->addLayout(buttomLayout);
this->m_OK = new QPushButton();
this->m_OK->setGeometry(QRect(230, 390, 77, 25));
this->m_OK->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->m_OK->setText(tr("OK"));
buttomLayout->addWidget(m_OK, 0, Qt::AlignRight);

this->m_Cancel = new QPushButton();
this->m_Cancel->setGeometry(QRect(310, 390, 77, 25));
this->m_Cancel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
buttomLayout->addWidget(m_Cancel);
this->m_Cancel->setText(tr("Cancel"));
}

wysota
6th July 2009, 08:26
Please provide something compilable, I'd like to play a bit with the code.

dotboy
6th July 2009, 11:31
This is the project(compressed by winrar, I added ".zip" at the end)...
Thx

wysota
6th July 2009, 11:53
Apart from weird mouse handling it works quite correct for me on Linux.

Here is a shot:

dotboy
6th July 2009, 14:10
No, didn't you see the tab is not showing correctly, and If you put a qtableView on the tabWidget, it'll also get itself shown correctly...
And about mouse handling, I'm dealing with that yet...

And you can compare the jpgs that I uploaded before, there is something different between the 2 QTableView. Around the Lable, one of them has color as the QPalette::Background, but the other one is looks like white.
In the project you build, you can click the tab to see what will happen...

wysota
6th July 2009, 14:39
Look... apparently my interpretation of a "minimal compilable example reproducing the problem" and yours differ greatly. I'm not going to read through serveral hundred lines of code with texts I don't understand to find a solution to a problem I don't see. Please provide a minimal compilable example clearly reproducing the problem, at most 100 lines of code in a total of one class plus the main function. Currently you have provided a bunch of classes that intend to do something but it is far from being clear what they do, how they are activated, etc.