PDA

View Full Version : QToolButton text alignment



Vladimir
1st March 2007, 14:42
Hello All !
I'm trying to implement toolbox which looks like widgets palette from Qt3 Desiger. I've created QToolBar and set its orientation to Vertical. For each added button I'm setting
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
But in Qt4 a text on buttons are centered ! Are there any way to set text alignment for QToolButton ? Or maybe there are better ways to implement such toolbox ?

wysota
1st March 2007, 15:26
Can't you use QToolBox?

Vladimir
1st March 2007, 16:16
Yes, I'm using it. My question was about content inside QToolBox.
I've already found a solution: QToolButton aligns text to left if it has icon and QToolBar is in Qt::ToolButtonTextBesideIcon mode.
Anyway, thanks for your reply.

wysota
1st March 2007, 20:12
The contents is most probably a QListView, at least it looks like one (notice the scrollbars if you reduce the toolbox size).

Vladimir
1st March 2007, 22:28
The contents is most probably a QListView, at least it looks like one (notice the scrollbars if you reduce the toolbox size).
According to function void MainWindow::setupToolbox() in
http://websvn.kde.org/tags/kdevelop/3.4.0/kdevdesigner/designer/mainwindow.cpp?revision=627088&view=markup
it must be QToolBar. But it has scrollbars, this really puzzles me !

With QListView its quite harder to implement toggle items like in designer3, isn't it ?

wysota
1st March 2007, 22:34
According to function void MainWindow::setupToolbox() in
http://websvn.kde.org/tags/kdevelop/3.4.0/kdevdesigner/designer/mainwindow.cpp?revision=627088&view=markup
it must be QToolBar. But it has scrollbars, this really puzzles me !
It doesn't look like a toolbar, at least in Qt Designer... But it doesn't mean it's not one :)


With QListView its quite harder to implement toggle items like in designer3, isn't it ?

No, why? You know when the item is selected or activated and then it's just a matter of painting it. With Qt4 it's even easier - QStyleOptionViewItem contains the full state of the item, along with its selected state (QStyle::State_Selected). Then you can paint the item accordingly.

Vladimir
2nd March 2007, 07:42
No, why? You know when the item is selected or activated and then it's just a matter of painting it. With Qt4 it's even easier - QStyleOptionViewItem contains the full state of the item, along with its selected state (QStyle::State_Selected). Then you can paint the item accordingly.
Ok, maybe QListView fits better for may task. I'll try using it.
And thanks a lot for you suggestion.