diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 38f215769..fc91dd4be 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -291,14 +291,14 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) } } - if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) { - QPoint relPoint = this->mapToParent(event->pos()); + QPoint relPoint = this->mapToParent(event->pos()); + if (this->mouseDown && !this->getDesiredRect().contains(relPoint)) { int index; - SplitContainer *clickedPage = notebook->tabAt(relPoint, index); + SplitContainer *clickedPage = notebook->tabAt(relPoint, index, this->width()); if (clickedPage != nullptr && clickedPage != this->page) { - this->notebook->rearrangePage(clickedPage, index); + this->notebook->rearrangePage(this->page, index); } } } diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 09a815443..0f026a15a 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -151,12 +151,15 @@ int Notebook::tabCount() return this->pages.size(); } -SplitContainer *Notebook::tabAt(QPoint point, int &index) +SplitContainer *Notebook::tabAt(QPoint point, int &index, int maxWidth) { int i = 0; for (auto *page : this->pages) { - if (page->getTab()->getDesiredRect().contains(point)) { + QRect rect = page->getTab()->getDesiredRect(); + rect.setWidth(std::min(maxWidth, rect.width())); + + if (rect.contains(point)) { index = i; return page; } @@ -250,6 +253,7 @@ void Notebook::performLayout(bool animated) if (this->selectedPage != nullptr) { this->selectedPage->move(0, y + tabHeight); this->selectedPage->resize(width(), height() - y - tabHeight); + this->selectedPage->raise(); } } diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index b137beb79..4c24d19a8 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -41,7 +41,7 @@ public: void performLayout(bool animate = true); int tabCount(); - SplitContainer *tabAt(QPoint point, int &index); + SplitContainer *tabAt(QPoint point, int &index, int maxWidth = 2000000000); void rearrangePage(SplitContainer *page, int index); void nextTab();