我在這裏遇到了問題。Qt Pb與QAction,QToolBar,QToolButton
我正在構建一個使用slidingStackedWidgets的Qt應用程序,以便從一個頁面滑動到另一個頁面。
我有2個工具欄,一個topToolBar和一個bottomToolBar,當中心控件移動時不會滑動。
所以我在mainWindow.h
QAction *backToMainVert;
在我mainWindow.cpp宣佈的QAction,當我通過點擊按鈕調用第二個觀點,我稱之爲是這樣一個slideInAdd()方法這樣的:
slidingStacked->slideInIdx(1); //this takes me back to my second page
backToMainVert = this->topToolBar->addWidget(backBarButton);
//this adds a backButton to the topToolBar
現在backBarButton被連接到被觸發時把我帶回到我的第一頁,並刪除backBarButton從topToolBar
一個slideToMain()方法我第一次切換到第二頁,沒問題,我的按鈕被創建並顯示在我的topToolBar上。
當我點擊backBarButton時,它會回到第一頁。
但是第二次我想從第一頁返回到第二頁,backBarButton從不出現。
呃,也許這可以幫助,這裏是我實例化我backBarButton方式:
backBarButton = new QToolButton(this);
backBarButton->setText("Retour");
backBarButton->setFixedSize(80,30);
backBarButton->setStyleSheet("background-image: url(:/ToolBarButton.png);"
"background-repeat: no-repeat;"
"background-position: center center;"
"border:0;"
"color : white;"
"font-family: System;"
"font-style: bold;"
"font-size: 9pt;"
"color : white;");
任何想法,我缺少在這裏嗎?
在此先感謝,我卡住了。
Miky邁克
的Hello World,
可能有人建議實現工具欄的另一種方式? 我希望自己能找到,但Qt 裏面的調試器並沒有給我太多的細節。它甚至不會停止在我的斷點上。 我應該從哪裏開始?
感謝您的幫助。
邁克
玉傢伙,
似乎要走的唯一方法是一個的QAction添加到topToolBar在slideInAdd()方法。
void MainWindow::slideInAdd(){
slidingStacked->setVerticalMode(true);
slidingStacked->slideInIdx(1);
backAction = new QAction(QIcon(":/ToolBarButton.png"), tr("&Retour"), this);
topToolBar->addAction(backAction);
connect(this->backAction,SIGNAL(triggered()),this, SLOT(slideInMainVert()));
}
,這在slideInMainVert()方法:
this->topToolBar->removeAction(backAction);
它的工作這種方式,但問題是,我無法弄清楚如何自定義出現在topToolBar的QToolButton。我希望它大於默認大小(比如說...100x30),上面有一些文字(就像一個按鈕一樣)。
請問您能幫我嗎?
非常感謝......
邁克