here's the way to manage buttons manually, without layout, but it also doesn't work fine
Qt Code:
  1. void PaletteToolbar::arrangeButtons()
  2. {
  3. if (buttonList.size()!=0)
  4. {
  5. arranging = true;
  6. foreach(PaletteToolbarButton* button, buttonList)
  7. {
  8. button->hide();
  9. }
  10. expandButton->hide();
  11. int cellWidth = buttonList.first()->minimumWidth()+2;
  12. int cellHeight = buttonList.first()->minimumHeight()+2;
  13. int maxWidth = cellWidth, maxHeight = cellHeight;
  14. bool vert = orientation()==Qt::Vertical;
  15. switch(static_cast<QMainWindow*>(parentWidget())->toolBarArea(this))
  16. {
  17. case Qt::LeftToolBarArea:
  18. expandButton->setArrowType(expanded? Qt::LeftArrow : Qt::RightArrow);
  19. break;
  20. case Qt::RightToolBarArea:
  21. expandButton->setArrowType(expanded? Qt::RightArrow : Qt::LeftArrow);
  22. break;
  23. case Qt::BottomToolBarArea:
  24. expandButton->setArrowType(expanded? Qt::DownArrow : Qt::UpArrow);
  25. break;
  26. case Qt::TopToolBarArea:
  27. expandButton->setArrowType(expanded? Qt::UpArrow : Qt::DownArrow);
  28. break;
  29. }
  30. if (!expanded)
  31. {
  32. int x, y;
  33. if (vert)
  34. {
  35. //setMinimumWidth(cellWidth);
  36. foreach(QToolBar* toolBar, getToolBarsAtThisSide())
  37. {
  38. if (toolBar->width() > maxWidth)
  39. maxWidth = toolBar->width();
  40. }
  41. //setMaximumWidth(maxWidth);
  42. resize(maxWidth,height());
  43. y = 10;
  44. x = (width()-cellWidth)/2;
  45. }
  46. else
  47. {
  48. //setMinimumHeight(cellHeight);
  49. foreach(QToolBar* toolBar, getToolBarsAtThisSide())
  50. {
  51. if (toolBar->height() > maxHeight)
  52. maxHeight = toolBar->height();
  53. }
  54. //setMaximumHeight(maxHeight);
  55. resize(width(),maxHeight);
  56. x = 10;
  57. y = (height()-cellHeight)/2;
  58. }
  59. foreach(PaletteToolbarButton* button, buttonList)
  60. {
  61. button->move(x,y);
  62. button->show();
  63. if (vert)
  64. {
  65. y += cellHeight;
  66. if (y + cellHeight*2 > height()) break;
  67. }
  68. else
  69. {
  70. x += cellWidth;
  71. if (x + cellWidth*2 > width()) break;
  72. }
  73. }
  74. expandButton->move(x,y);
  75. expandButton->show();
  76. }
  77. else //PaletteBar is expanded
  78. {
  79. int x, y, buttonStrings, maxButtonsInString;
  80. if (vert)
  81. {
  82. maxButtonsInString = height() / cellHeight;
  83. buttonStrings = (buttonList.size() + 1) / maxButtonsInString;
  84. if (buttonList.size() % maxButtonsInString) ++buttonStrings;
  85. //setMinimumWidth(cellWidth * buttonStrings);
  86. //QPoint newpos = pos();
  87. //newpos.setX(newpos.x() - (cellWidth * buttonStrings - 1));
  88. //move(newpos);
  89. QSize s=maximumSize();
  90. QSize s1=minimumSize();
  91. resize(cellWidth * buttonStrings,height());
  92. QSize s2=size();
  93. y = 10;
  94. x = 1;
  95. }
  96. else
  97. {
  98. maxButtonsInString = width() / cellWidth;
  99. buttonStrings = (buttonList.size() + 1) / maxButtonsInString;
  100. if (buttonList.size() % maxButtonsInString) ++buttonStrings;
  101. //setMinimumHeight(cellHeight * buttonStrings);
  102. //QPoint newpos = pos();
  103. //newpos.setY(newpos.y() + (cellHeight * buttonStrings - 1));
  104. //move(newpos);
  105. resize(width(),cellHeight * buttonStrings);
  106. y = 1;
  107. x = 10;
  108. }
  109. foreach(PaletteToolbarButton* button, buttonList)
  110. {
  111. button->move(x,y);
  112. button->show();
  113. if (vert)
  114. {
  115. y += cellHeight;
  116. if (y + cellHeight*2 > height())
  117. {
  118. y = 10;
  119. x += cellWidth;
  120. }
  121. }
  122. else
  123. {
  124. x += cellWidth;
  125. if (x + cellWidth*2 > width())
  126. {
  127. x = 10;
  128. y += cellHeight;
  129. }
  130. }
  131. }
  132. expandButton->move(x,y);
  133. expandButton->show();
  134.  
  135. if (vert)
  136. {
  137. maxButtonsInString = height() / cellHeight;
  138. buttonStrings = (buttonList.size() + 1) / maxButtonsInString;
  139. if (buttonList.size() % maxButtonsInString) ++buttonStrings;
  140. //setMinimumWidth(cellWidth * buttonStrings);
  141. //QPoint newpos = pos();
  142. //newpos.setX(newpos.x() - (cellWidth * buttonStrings - 1));
  143. //move(newpos);
  144. QSize s=maximumSize();
  145. QSize s1=minimumSize();
  146. resize(cellWidth * buttonStrings,height());
  147. QSize s2=size();
  148. y = 10;
  149. x = 1;
  150. }
  151. else
  152. {
  153. maxButtonsInString = width() / cellWidth;
  154. buttonStrings = (buttonList.size() + 1) / maxButtonsInString;
  155. if (buttonList.size() % maxButtonsInString) ++buttonStrings;
  156. //setMinimumHeight(cellHeight * buttonStrings);
  157. //QPoint newpos = pos();
  158. //newpos.setY(newpos.y() + (cellHeight * buttonStrings - 1));
  159. //move(newpos);
  160. resize(width(),cellHeight * buttonStrings);
  161. y = 1;
  162. x = 10;
  163. }
  164. }
  165. arranging = false;
  166. QSize s3=size();
  167. }//if (buttonList.size()!=0)
  168. }
  169. QList<QToolBar*> PaletteToolbar::getToolBarsAtThisSide()
  170. {
  171. QList<QToolBar*> ret;
  172. QMainWindow* mainWnd = static_cast<QMainWindow*>(parentWidget());
  173. Qt::ToolBarArea area = mainWnd->toolBarArea(this);
  174. foreach(QObject* object, mainWnd->children())
  175. {
  176. if (object!=this)
  177. if (QToolBar* toolBar = dynamic_cast<QToolBar*>(object))
  178. {
  179. if (area == mainWnd->toolBarArea(toolBar))
  180. ret.append(toolBar);
  181. }
  182. }
  183. return ret;
  184. }
To copy to clipboard, switch view to plain text mode