2010-04-09 158 views
0

我遇到了一些奇怪的行为,带有分页的QDockWidgets,下面是一个带有注释的示例程序,演示了这种行为。QDockWidget和setFloating可能存在的bug()

这是一个错误还是它的预期行为,我错过了QDockWidget中的一些细微差别,导致这一点?

直接,因为这不起作用,如何恰当地“隐藏”隐藏的QDockWidget然后显示它?

#include <QApplication> 
#include <QMainWindow> 
#include <QAction> 
#include <QDockWidget> 
#include <QMenu> 
#include <QSize> 
#include <QMenuBar> 

using namespace std; 

int main (int argc, char* argv[]) 
{ 
    QApplication app(argc, argv); 
    QMainWindow window; 
    QDockWidget dock1(&window); 
    QDockWidget dock2(&window); 
    QMenu menu("View"); 

    dock1.setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 
    dock2.setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 

    dock1.setWindowTitle("Dock One"); 
    dock2.setWindowTitle("Dock Two"); 

    window.addDockWidget(Qt::RightDockWidgetArea, &dock1); 
    window.addDockWidget(Qt::RightDockWidgetArea, &dock2); 
    window.menuBar()->addMenu(&menu); 
    window.setMinimumSize(QSize(800, 600)); 

    window.tabifyDockWidget(&dock1, &dock2); 

    dock1.hide(); 
    dock2.hide(); 

    menu.addAction(dock1.toggleViewAction()); 
    menu.addAction(dock2.toggleViewAction()); 



    window.show(); 

    // Below is where the oddness starts. It seems to only exhibit the 
    // behavior if the dock widgets are tabified. 


    // Odd behavior here 
    // This does not work. the window never shows, though its menu action shows 
    // checked. Not only does this window not show up, but all toggle actions 
    // for all dock windows (e.g. dock1 and dock2) are broken for the duration 
    // of the application loop. 
    // dock1.setFloating(true); 
    // dock1.show(); 


    // This does work. . . of course only if you do _not_ run the above first. 
    // however, you can often get a little lag or "blip" in the rendering as 
    // the dock is shown docked before setFloating is set to true. 
    dock1.show(); 
    dock1.setFloating(true); 
    return app.exec(); 
} 

回答

1

它看起来像“setFloating(true)”的情况下显示窗口之前它仍然显示,但有“屏幕外”的位置,所以你看不到它。试着改变你的代码,以水木清华这样的:

dock1.setFloating(true); 
qDebug() << "old size: " << dock1.size() << " old pos: " << dock1.pos(); 
dock1.resize(QSize(200, 200)); // set new size for the dock window 
dock1.move(QPoint(50, 50)); // set new position for the dock window 
dock1.show(); 

我相信这应该让你的显示窗口, 问候

+0

谢谢,这点上。 – jkyle 2010-04-13 18:38:09

相关问题