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. QDockWidget will not go from Floating back to the docked state, why?
QtWS25 Last Chance

QDockWidget will not go from Floating back to the docked state, why?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 9.7k Views
  • 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.
  • J Offline
    J Offline
    jeremy_c
    wrote on last edited by
    #1

    This is my widget, it's pretty simple right now so I've just included all the code. The dock appears just fine, I can resize it just fine also.
    The problem is that when I try to drag it, it will not dock anywhere, even the place it just came from. It will turn into a floating window, but that's it.

    Thanks for any help.

    @
    ClockWidget::ClockWidget(QWidget *parent) : QFrame(parent)
    {
    QGridLayout *lay = new QGridLayout(this);

    theirTitleLabel = new QLabel(tr("Their"));
    qsoTitleLabel = new QLabel(tr("QSO"));
    
    utcLabel = new QLabel("Sun 00, 0000");
    localLabel = new QLabel("Sun 00, 00:00mm");
    theirLabel = new QLabel("Sun 00, 00:00mm");
    qsoLabel = new QLabel("00:00:00");
    
    lay->addWidget(new QLabel(tr("UTC")), 0, 0, Qt::AlignRight);
    lay->addWidget(utcLabel, 0, 1);
    lay->addWidget(new QLabel(tr("Local")), 1, 0, Qt::AlignRight);
    lay->addWidget(localLabel, 1, 1);
    lay->addWidget(theirTitleLabel, 2, 0, Qt::AlignRight);
    lay->addWidget(theirLabel, 2, 1);
    lay->addWidget(qsoTitleLabel, 3, 0, Qt::AlignRight);
    lay->addWidget(qsoLabel, 3, 1);
    
    setLayout(lay);
    
    updateClock();
    

    }

    void ClockWidget::updateClock()
    {
    QDateTime local = QDateTime::currentDateTime();
    QDateTime utc = local.toUTC();

    utcLabel->setText(utc.toString("ddd dd, hh:mm"));
    localLabel->setText(local.toString("ddd dd, hh:mm"));
    

    }

    QDockWidget *ClockWidget::createDockWidget(QWidget *parent)
    {
    QDockWidget *dock = new QDockWidget(tr("Clock"), parent);
    dock->setAllowedAreas(Qt::TopDockWidgetArea |
    Qt::BottomDockWidgetArea |
    Qt::LeftDockWidgetArea |
    Qt::RightDockWidgetArea);
    dock->setFeatures(QDockWidget::DockWidgetClosable |
    QDockWidget::DockWidgetFloatable |
    QDockWidget::DockWidgetMovable);
    dock->setWidget(this);

    return dock;
    

    }
    @

    In my main window class (inherited from QMainWindow):

    @
    QDockWidget *dock;
    clockWidget = new ClockWidget(this);
    dock = clockWidget->createDockWidget(this);
    addDockWidget(Qt::RightDockWidgetArea, dock);
    toolsMenu->addAction(dock->toggleViewAction());
    @

    That's a bit more complex than it needs to be but I was goofing around with things trying to make it work.

    Jeremy
    http://www.kb8lfa.com

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Tested your code, works fine for me.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jeremy_c
        wrote on last edited by
        #3

        You can undock and dock the widget? For me I cannot dock the widget once it has been undocked. I found that if I comment out the line:

        @dock->setWidget(this)@

        then the dock frame can undock/dock just fine all day long. It has no content, but it can be moved around to any location, made floatable, re-docked, etc...

        Any thoughts?

        Jeremy
        http://www.kb8lfa.com

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jeremy_c
          wrote on last edited by
          #4

          Ah, never mind. I figured it out. It seems that the widget is docked but when it undocks Qt doesn't think there is enough room in the main window for it to redock. If I make the window larger, it will then dock again. I just assumed that it came from the main window and it could then return to the main window but I guess that's not the case.

          Jeremy
          http://www.kb8lfa.com

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            That makes sense. Good to see you figured it out.

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rhodanos
              wrote on last edited by
              #6

              I have kind of the same problem like jeremy_c, only in my case everything workes great if I have the MainWindow in window mode. As soon as I set the window to fullscreen the docking will not work anymore. The interesting part is, that the location where the QDockWidget should dock has even more free space then it has in window mode?

              I use the QDockWidget with QtDesigner and set all flags I need there.

              Any suggestions?

              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