PDA

View Full Version : QDockWidget floating as a window



splinterz
7th December 2013, 23:23
i've got a little class which allows dockwidgets to be minimzed or closed once they're floating. on windows, this works without issue, however on linux (ubuntu) when the qdockwidgets are 'undocked' and floating, they don't draw, they're black rectangles. the really weird part, is if i step through with the debugger in the 'floating_changed' below, they show up properly?

is there a better way to accomplish this?



class BaseDock : public QDockWidget {
Q_OBJECT
public:
BaseDock(QWidget *parent = 0, Qt::WindowFlags flags = 0)
:QDockWidget(parent,flags)
{
connect(this,SIGNAL(topLevelChanged(bool)),this,SL OT(floating_changed(bool)));
}

private slots:
void floating_changed(bool floating){
if(this->isVisible() && floating){
this->setWindowFlags(Qt::Window);
QPoint pos = this->pos();
if(pos.x() < 0)
pos.setX(0);
if(pos.y() < 0)
pos.setY(0);
this->move(pos);
this->show();
}
}

};

splinterz
8th December 2013, 13:21
alright after more tinkering i've revised the slot's code, which seems to work better:


void floating_changed(bool floating){
bool vis = this->isVisible();
if(floating){
this->setWindowFlags(Qt::Window);
QPoint pos = this->pos();
if(pos.x() < 0)
pos.setX(0);
if(pos.y() < 0)
pos.setY(0);
this->move(pos);

if(vis)
this->show();
}
}


now the issue persists on linux only under a particular circumstance. first let me show the code that initializes the docks, in case there's something wrong there. all docks are setup like this:


PreferencesDock *pref_dock = new PreferencesDock(this); //this dock inherits the baseDock outlined in the first post.
pref_dock->setHidden(true);
pref_dock->setFloating(false);
addDockWidget(Qt::RightDockWidgetArea, pref_dock);

ui->menu_docks->addAction(pref_dock->toggleViewAction());

so, when running in windows all is fine. under linux (ubuntu) if a dock is added to a dock area on the sides of the application, and then you click the little 'undock' button to pop it out, that's when the issue occurs. it pops out the dock (floating mode) but, it doesn't draw it. it's just a rectangle on the screen where it should be.

the above 'floating_changed' is being called when it's popped out to floating mode, and if i put a break point in that code, then the dock is properly drawn as expected!?