Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Building a special windows bar



  • 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


  • Lifetime Qt Champion

    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 ?



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


  • Lifetime Qt Champion

    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.


  • Lifetime Qt Champion

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


  • Lifetime Qt Champion

    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.



  • Thank you very much!!


  • Lifetime Qt Champion

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


Log in to reply