質問

I created tab with:

ui->tabWidget->addTab(widgetTab,"Title");

I want to add a refresh button after tab text "Title". How can I do that?

役に立ちましたか?

解決

I don't believe you can directly. The QTabBar element of QTabWidget is only accessible via the tabBar() member function, which is protected. And QTabBar's setTabButton isn't exposed otherwise in the tab widget's interface.

You could do it by subclassing QTabWidget though. Something like:

class MyTabWidget: public QTabWidget
{
    Q_OBJECT

    public:
        MyTabWidget(QWidget *parent = 0)
            : QTabWidget(parent)
        {
            addTab(new QLabel("foo"), "foo");
            addTab(new QLabel("bar"), "bar");
            QPushButton *b1 = new QPushButton("<");
            QPushButton *b2 = new QPushButton(">");
            tabBar()->setTabButton(0, QTabBar::LeftSide, b1);
            tabBar()->setTabButton(1, QTabBar::RightSide, b2);
        }
};
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top