Qt 小記載

來源:互聯網
上載者:User

1 在MainWindow中

setAttribute(Qt::WA_DeleteOnClose);

在main()函數中如果

MainWindoiw win;

win.show();

當關閉程式時會報錯,可以修改為

MainWindow * min = new MainWindow;

原因一個在堆上一個在棧上,setAttribute(Qt::WA_DeleteOnClose);之後會調用delete
(win)

 

2 在QTabWidget上可以設定小按鈕在哪個角落

        addTabButton=newQToolButton(this);

    addTabButton->setDefaultAction(m_newTabAction);
    addTabButton->setAutoRaise(true);
    addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
    setCornerWidget(addTabButton, Qt::TopRightCorner);
    addTabButton->show();

這樣可以在tabwidget的右上方顯示按鈕

 

3 QtabWidget 為每個標籤設定關閉按鈕

          this->tabBar()->setTabsClosable(true);

實際上就是QTabBar的方法,設定之後當點擊關閉按鈕會發射訊號

         tabCloseRequeseted();

 

4 QTabBar裡面設定

        setContextMenuPolicy(Qt::CustomContextMenu);

This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu,
and the user has requested a context menu on the widget. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates.

設定 setContextMenuPolicy(Qt::CustomContextMenu) 會發射

:customContextMenuRequested ( const QPoint & pos ) [signal]

 

5 等待游標

         QApplication::setOverrideCursor(Qt::WaitCursor);

    QApplication::restoreOverrideCursor();

 

6使用 QTabWidget時候需要注意,如果要用addTab()函數,在TabBar上出現三角的小按鈕,你需要在

         setTabBar(m_tabBar);

    setDocumentMode(true);
如果在setTabBar前面用的setDocumentMode(true)會出現當添加一個tab的時候出現小三角,這裡是用了自訂的TabBar
 

7在QTabWidget裡設定 setTabsClosable(true); 當點擊每個tab上的關閉按鈕的時候會發射

tabCloseRequested(); 訊號

 

8 在QTabBar setMoveable(true) tabBar的標籤可以移動,

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.