SetWindowFlags() in ubuntu 12.04 Unity
-
Hello.
I've some question. When I set setWindowFlags() my window is hidden.
When I execute this code:
@
w.setWindowFlags(Qt::FramelessWindowHint);
w.show();
@On Unity-bar (left panel with icons) 2 icons of my application randomly appear on this bar.
Is anybody know about this?
-
try this:
w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint);
w.show(); -
I tried it and I got same result.
PS. I'm interested to know, may be this bug of Qt or Unity?
-
Can you paste your code here?
-
@
class A : public QMenu
{
Q_OBJECT
public:
A(QWidget *parent = 0);
// In here defined interfaces ...signals:
void titleHidden();private:
void createActions();private:
QAction *windowTitle;
};A::A(QWidget *parent)
: QMenu(parent)
{
createActions();
}void A::createActions()
{
windowTitle = new QAction(this);
connect(windowTitle, SIGNAL(triggered()), SIGNAL(titleHidden()));
}class B : public QWidget
{
Q_OBJECT
public:
B(QWidget *parent = 0);
// In here defined interfaces ...private slots:
void hideTitle();private:
A *contextMenu;
};B::B(QWidget *parent)
: QWidget(parent),
contextMenu(new A(this))
{
connect(contextMenu, SIGNAL(titleHidden()), SLOT(hideTitle()));
}void B::hideTitle()
{
// NOTE: first impl
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);// NOTE: second impl // setWindowFlags(windowFlags() | Qt::FramelessWindowHint); // show();
}
@ -
If your intention is to hide title bar, then you can simply use
m_OldFlags = windowFlags(); //m_OldFlags being a class member to hold the old flags.
setWindowFlags(Qt::CustomizeWindowHint). -
Your answer wrong. You don't understand my question.
What do you offer do with m_OldFlags?
This is useless member of class.
This string of code
@
setWindowFlags(Qt::CustomizeWindowHint)
@is not decides my problem.
PS. Just I test my code on OS Windows 7. It has same behaviour.
-
m_OldFlags was just for a backup. However I got the problem. As per Qt documentation for setWindowFlags(), there is a problem by setting windows flag after widget is shown.
This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again..
Try re-implementing QWidget::hideEvent ( QHideEvent * event ) and set a member boolean value inside void B::hideTitle() so as to detect that the hideEvent is a result of setting window flags, there by ignoring the event and reset the member boolean value after.
-
Seems I understood this problem.
In my opinion, we should set flags before show widget.
In other situation (e.g. as in my case) we need write code as:
@
setWindowFlags(/some Qt::WindowFlags/);
show();
@For DE Unity (Ubuntu 12.04) this code causes random appear of 2 icons on the unity task bar.
For Windows 7 this code has correct work.Thanks, for discussion.
PS. If anybody know more about this, please, write in here.
-
adaitabehera, thanks. But i tried overriding hideEvent().
About backup flags - what for?Key word - flags.
If you want to cancel your applied flag, you should use bit operation "^". If you want find into windowFlags() concrete flag, you should use bit operation "&".
For example:
@
if (windowFlags() & Qt::FramelessWindowHint)
setWindowFlags(windowFlags() ^ Qt::FramelessWindowHint);
else
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
@To escape repeated, windowFlags() can be handed into const variable. E.g.:
@
Qt::WindowFlags flags = windowFlags();
@ -
ohh!!! my mistake...hideEvent() is called after widget is hidden not before..so no use. You need to catch some event that is triggered before widget hiding...I don't know if any such event in Qt that serve the purpose.
-
yes you are correct..we can use bit wise operators as well, but anyway that is not the problem of discussion.
-
So people this problem is not solved yet? I am trying to avoid that too, and the solution of changing flag before show() is not working at my case, because i have to keep window always on top with a button and every time my app flashing on pressing that button.