Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetWindowFlags() in ubuntu 12.04 Unity
Forum Updated to NodeBB v4.3 + New Features

SetWindowFlags() in ubuntu 12.04 Unity

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 5.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • adaitabeheraA Offline
    adaitabeheraA Offline
    adaitabehera
    wrote on last edited by
    #2

    try this:

    w.setWindowFlags(w.windowFlags() | Qt::FramelessWindowHint);
    w.show();

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ruu_Rinki
      wrote on last edited by
      #3

      I tried it and I got same result.

      PS. I'm interested to know, may be this bug of Qt or Unity?

      1 Reply Last reply
      0
      • adaitabeheraA Offline
        adaitabeheraA Offline
        adaitabehera
        wrote on last edited by
        #4

        Can you paste your code here?

        C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruu_Rinki
          wrote on last edited by
          #5

          @
          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();
          

          }
          @

          1 Reply Last reply
          0
          • adaitabeheraA Offline
            adaitabeheraA Offline
            adaitabehera
            wrote on last edited by
            #6

            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).

            C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ruu_Rinki
              wrote on last edited by
              #7

              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.

              1 Reply Last reply
              0
              • adaitabeheraA Offline
                adaitabeheraA Offline
                adaitabehera
                wrote on last edited by
                #8

                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.

                C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Ruu_Rinki
                  wrote on last edited by
                  #9

                  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.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Ruu_Rinki
                    wrote on last edited by
                    #10

                    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();
                    @

                    1 Reply Last reply
                    0
                    • adaitabeheraA Offline
                      adaitabeheraA Offline
                      adaitabehera
                      wrote on last edited by
                      #11

                      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.

                      C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

                      1 Reply Last reply
                      0
                      • adaitabeheraA Offline
                        adaitabeheraA Offline
                        adaitabehera
                        wrote on last edited by
                        #12

                        yes you are correct..we can use bit wise operators as well, but anyway that is not the problem of discussion.

                        C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Crackeraki
                          wrote on last edited by
                          #13

                          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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved