Results 1 to 5 of 5

Thread: Palette toolbar need help plz...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    57
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 1 Time in 1 Post

    Default Re: Palette toolbar need help plz...

    wysota
    I've put the whole code in the first time and it's the best I can do as I am new to Qt. I'm sure that when it is finished it will be a very useful widget for many people and also a good lesson of toolbars and layouts usage.

  2. #2
    Join Date
    Jun 2008
    Posts
    57
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 1 Time in 1 Post

    Default Re: Palette toolbar need help plz...

    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 

Similar Threads

  1. unable to hide combobox or spinbox in toolbar
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2008, 11:52
  2. Palette toolbar
    By Radagast in forum Qt Programming
    Replies: 8
    Last Post: 7th July 2008, 17:56
  3. Palette Frame
    By csvivek in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2008, 05:34
  4. Create a Toolbar on a Subclassed Textedit?
    By c_07 in forum Qt Programming
    Replies: 5
    Last Post: 12th October 2007, 18:17
  5. animating a toolbar??!?
    By nupul in forum Qt Programming
    Replies: 4
    Last Post: 1st April 2006, 08:27

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
  •  
Qt is a trademark of The Qt Company.