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. Building a special windows bar
Forum Updated to NodeBB v4.3 + New Features

Building a special windows bar

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 716 Views 2 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.
  • P Offline
    P Offline
    ppp1
    wrote on last edited by aha_1980
    #1

    Hello,
    can anyone give me an hint how to built an item in QT that is similar to this windows bar in the picture.
    This bar is fixed above the status bar and can be closed. I don't want to have codes. An approximate instruction is ok.

    Bar

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums
      You could use a QFrame with a layout to hold the widgets.
      You could just use Designer to make it.

      To fix it above statusbar, you can override the resize event on MainWindow and place it correctly
      when windows is resized.

      When closing it. You can simply hide() it so its ready to be shown again.

      you can use a QPropertyAnimation to make it slide open if you want it a bit fancy :)
      (like this menu does https://github.com/chrisaverage/burger-menu/blob/master/src/burgermenu.cpp)

      Not sure what else to say ?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        ppp1
        wrote on last edited by
        #3

        Hello,
        thank you for the information. I thought and hoped that QT has build in item for that. I will try to design it with QFrame tomorrow.
        Is it possible to put the X(Quit) on the left side? In QT I just now that the quit button is in the top right of a window/widget.

        mrjjM 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          The window decoration is not handled at all by Qt. It's the window manager of your OS that manages them.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • P ppp1

            Hello,
            thank you for the information. I thought and hoped that QT has build in item for that. I will try to design it with QFrame tomorrow.
            Is it possible to put the X(Quit) on the left side? In QT I just now that the quit button is in the top right of a window/widget.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ppp1
            Hi
            Your bar would likely be embedded into MainWindow and hence not be a window and therefore have
            no default X button but you can make one your self.
            There is no such dedicated class but you could use a toolbar or other statusbar if it has features you need but
            judging from the image, its just a bunch of widgets in a layout.

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              Hi
              Instead of using Mainwindows resize event, you could also use an event filter to have it follow the
              statusbar and be a more self-contained custom widget.
              https://doc.qt.io/qt-5/eventsandfilters.html

              I know you dont want code but its easier to explain than with words

              class ExtraBar : public QWidget
              {
                  Q_OBJECT
                  QWidget *FixToWidget;
              public:
                  explicit ExtraBar(QWidget *parent, QWidget *TheFixToWidget);
                  ~ExtraBar() override;
              private:
                  Ui::ExtraBar *ui;
              protected:
                  bool eventFilter(QObject *obj, QEvent *ev) override
                  {
                      if (!obj->isWidgetType() || !FixToWidget) return false;
                      // the parent is being resized
                      if (ev->type() == QEvent::Resize) {
                          auto g = FixToWidget->geometry(); // take the statusbar location
                          setGeometry(0, g.y() - height() - 2, g.width(), height()); // make us stay on top of it
                      }
                      return false;
                  }
              };
              

              You can then assign it a parent and a status bar
              ( in ctor of mainwindow)
              auto bar = new ExtraBar(this, ui->statusbar);

              and it works quite well without anything to be done in MainWinow
              alt text

              (i painted staturbar red so its easier to see)

              Demo project
              https://www.dropbox.com/s/joah7ume9hcx8e5/ExtraBarTest.zip?dl=0

              I made the bar with UI file so its easy to fill it out with teh wanted widgets.

              1 Reply Last reply
              3
              • P Offline
                P Offline
                ppp1
                wrote on last edited by
                #7

                Thank you very much!!

                mrjjM 1 Reply Last reply
                0
                • P ppp1

                  Thank you very much!!

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @ppp1
                  Np. It just a very fast sample ( 5 mins ) to see if event filter would work as i excepted.
                  The bar itself will need some love to look good and be closeable.

                  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