Close button only for some tabs in Qt

后端 未结 7 2103
天命终不由人
天命终不由人 2021-02-05 05:22

I am using Qt for an assignment I have for college, and I want to use QTabWidget to display a chat window much like Pidgin\'s. I want to make the \"group chat\" tab

7条回答
  •  半阙折子戏
    2021-02-05 05:57

    Hallo,

    I guess this post won't help the author of this thread but perhaps someone else wanders over here.

    In most cases a non-closable tab should not only ignore the closevent it also should not show a close symbol in its corner. A nice way to reach this is to modify the QTabBar which is inside the QTabWidget.

    Example:

    // let tabWidget be a QTabWidget with at least one page
    
    QPushButton *closeButton = new QPushButton();
    // set icon and size for PushButton, ... 
    // connect Signal clicked() from closeButton with Slot closeCurrentTab(), ...
    
    // next line sets closeButton in right corner on tab with index 0
    tabWidget->tabBar()->setTabButton(0, QTabBar::RightSide, closeButton);
    

提交回复
热议问题