QTabWidget tabs on the vertical, but text in horizontal

独自空忆成欢 提交于 2019-12-03 11:48:55

问题


I'm trying to make an app in C++ Qt with a sidebar like this one:

But when making QTabWidget's orientation to West, it makes the text vertical. How to have the text on the left, but horizontally-aligned? Ps: I don't need icons. Thanks in advance.


回答1:


You can use QListWidget to show the "tabs" (with some mods to make it look like you want) and QStackedWidget to handle switching between pages like normal tab widget does.




回答2:


A bit of "advertising" for a WTFPL implementation here on assembla Any contribution will be much appreciated.




回答3:


use QProxyStyle, this function will rotate 180 for text, and you can rotate 90。

void MyProxyStyle::drawItemText( QPainter* painter,
                                 const QRect&,
                                 int alignment,
                                 const QPalette& palette,
                                 bool enabled,
                                 const QString& text,
                                 QPalette::ColorRole textRole ) const
{
    painter->save();
    painter->translate(160,50);
    painter->rotate(-180);

    QCommonStyle::drawItemText( painter,
                                rectangle,
                                alignment,
                                palette,
                                enabled,
                                text,
                                textRole );

    painter->restore();
}


来源:https://stackoverflow.com/questions/14299651/qtabwidget-tabs-on-the-vertical-but-text-in-horizontal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!