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:
Qt Code:
  1. DDialog::DDialog(QWidget* parent)
  2. :QWidget(parent, Qt::FramelessWindowHint | Qt::Dialog)
  3. {
  4. //this->setAutoFillBackground(true); //if it is set the top-level window was not transparent
  5. //if not, the child widget was not show correctly
  6. this->setAttribute(Qt::WA_TranslucentBackground);
  7. this->move(50, 50);
  8. this->resize(420, 430);
  9. this->Initialize();
  10. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void DDialog::Initialize()
  2. {
  3. QVBoxLayout* layout = new QVBoxLayout(this);
  4. this->setLayout(layout);
  5. layout->setMargin(0);
  6. layout->setSpacing(0);
  7. //TitleBar ZONE
  8. this->m_titleBar = new DTitleBar(this);
  9. layout->addWidget(m_titleBar);
  10.  
  11. this->m_mainWidget = new QWidget();
  12. layout->addWidget(m_mainWidget);
  13. m_mainWidget->setAutoFillBackground(true);
  14.  
  15. QStatusBar* statusBar = new QStatusBar();
  16. layout->addWidget(statusBar);
  17. statusBar->setAutoFillBackground(true);
  18. QVBoxLayout* centerLayout = new QVBoxLayout();
  19. this->m_mainWidget->setLayout(centerLayout);
  20.  
  21. //TabWidget ZONE
  22. this->m_tabWidget = new QTabWidget();
  23. this->m_tabWidget->setAttribute(Qt::WA_OpaquePaintEvent);
  24. centerLayout->addWidget(this->m_tabWidget);
  25. centerLayout->setMargin(10);
  26. this->m_tabWidget->setAutoFillBackground(true);
  27.  
  28. m_tabWidget->setGeometry(QRect(20, 20, 381, 361));
  29. this->m_tabWidget->setTabPosition(QTabWidget::North);
  30. this->m_tabWidget->setTabShape(QTabWidget::Rounded);
  31. this->m_tabWidget->setElideMode(Qt::ElideMiddle);
  32.  
  33. //TableView ZONE
  34. this->m_bmpTableHView = new QTableView();
  35. this->m_bmpTableIView = new QTableView();
  36. this->m_bmpTableHView->setAutoFillBackground(true);
  37. this->m_bmpTableIView->setAutoFillBackground(true);
  38. this->m_bmpTableHView->setGeometry(QRect(-10, -10, 391, 351));
  39. this->m_bmpTableHView->setFrameShadow(QFrame::Sunken);
  40. this->m_tabWidget->addTab(this->m_bmpTableHView, "BitMapHead");
  41. this->m_tabWidget->addTab(this->m_bmpTableIView, "BitMapInfoHead");
  42.  
  43. //QStandardItemModel ZONE
  44. this->m_tableHModel = new QStandardItemModel(4, 3, this);
  45. this->m_tableHModel->setHeaderData(0, Qt::Horizontal, tr("Name"));
  46. this->m_tableHModel->setHeaderData(1, Qt::Horizontal, tr("Bytes"));
  47. this->m_tableHModel->setHeaderData(2, Qt::Horizontal, tr("Value"));
  48. this->m_bmpTableHView->setModel(this->m_tableHModel);
  49.  
  50. this->m_tableIModel = new QStandardItemModel(4, 3, this);
  51. this->m_tableIModel->setHeaderData(0, Qt::Horizontal, tr("Name"));
  52. this->m_tableIModel->setHeaderData(1, Qt::Horizontal, tr("Bytes"));
  53. this->m_tableIModel->setHeaderData(2, Qt::Horizontal, tr("Value"));
  54. this->m_bmpTableIView->setModel(this->m_tableIModel);
  55.  
  56. //BUTTON ZONE
  57. QHBoxLayout* buttomLayout = new QHBoxLayout();
  58. centerLayout->addLayout(buttomLayout);
  59. this->m_OK = new QPushButton();
  60. this->m_OK->setGeometry(QRect(230, 390, 77, 25));
  61. this->m_OK->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  62. this->m_OK->setText(tr("OK"));
  63. buttomLayout->addWidget(m_OK, 0, Qt::AlignRight);
  64.  
  65. this->m_Cancel = new QPushButton();
  66. this->m_Cancel->setGeometry(QRect(310, 390, 77, 25));
  67. this->m_Cancel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
  68. buttomLayout->addWidget(m_Cancel);
  69. this->m_Cancel->setText(tr("Cancel"));
  70. }
To copy to clipboard, switch view to plain text mode