Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2046

Title bar on floating QToolBar

    XMLWordPrintable

Details

    Description

      At present, Qt 4.4.0 does not support floating QToolBars which have a title bar.

      This functionality is quite common and for instance can be found in Microsoft Office, Visual Studio, OpenOffice and Perforce GUI applications.

      Here is an example which comes very close to replicating this behavior; however it is not quite right:

      #include <QtGui>

      class ToolBar : public QToolBar
      {
      Q_OBJECT
      public:
      ToolBar(const QString &title, QWidget *parent = 0)
      : QToolBar(title, parent), recursion(false)
      {
      }

      void showEvent(QShowEvent *event)
      {
      if(isFloating()){
      if(recursion)

      { recursion = false; }

      else

      { recursion = true; hide(); setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint); setFixedSize(sizeHint()); show(); }

      } else

      { setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); setMinimumSize(0, 0); }

      QToolBar::showEvent(event);
      }
      private:
      bool recursion;
      };

      class MainWindow : public QMainWindow
      {
      Q_OBJECT
      public:
      MainWindow(QWidget *parent = 0)
      : QMainWindow(parent)

      { QMenu *file = menuBar()->addMenu("&File"); file->addAction("&Quit", this, SLOT(close())); QWidget *w = new QWidget(this); setCentralWidget(w); QVBoxLayout *layout = new QVBoxLayout(w); ToolBar *tb1 = new ToolBar("tb1"); tb1->addAction(QIcon(QPixmap(20,20)), "action"); addToolBar(Qt::TopToolBarArea, tb1); }

      };

      #include "main.moc"

      int main(int argc, char **argv)
      {
      QApplication a(argc, argv);
      MainWindow mw;
      mw.show();
      return a.exec();
      }

      This example shows that the behavior is definitely possible.

      There should at least be an option to enable/disable title bars on floating QToolBars rather than assume that the user does not want/need them.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              gpf Shane McLaughlin
              Votes:
              8 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes