aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-10-21 10:45:47 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-10-22 10:15:44 +0200
commit4e9c35588ccb72f09df61b81a748bde92286b45e (patch)
treed2289c6a2ea90c4331463a5b9d8b28b0dd6b9d5a /examples
parent75218552031152de935c9fd3290fb903da0a3d92 (diff)
Music player: Fix progress and thumb nail toolbar
A valid window handle must be set for this to work. Delay this until QWidget::show() and add documentation. Fixes: QTBUG-79348 Change-Id: Ib7db9568e0d70cb6194176f2da95a3b2087e403f Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc16
-rw-r--r--examples/winextras/musicplayer/musicplayer.cpp14
-rw-r--r--examples/winextras/musicplayer/musicplayer.h1
3 files changed, 26 insertions, 5 deletions
diff --git a/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc b/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc
index 8908699..8b8fd57 100644
--- a/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc
+++ b/examples/winextras/musicplayer/doc/src/qtwinextras-musicplayer.qdoc
@@ -100,9 +100,19 @@
\image qtwinextras-musicplayer-taskbar.png Screenshot of the Music Player taskbar
- The following snippet shows how the taskbar button is prepared. The playback
- progress is wired directly to the taskbar progress indicator by using signals
- and slots.
+ The following snippets show how the taskbar button is prepared.
+
+ For the taskbar and the thumbnail toolbar to work, a native window handle
+ must be set by passing an instance of \c QWindow to
+ \c QWinTaskbarButton::setWindow() or \c QWinThumbnailToolBar::setWindow(),
+ respectively. This instance is created in the process of \c QWidget::show()
+ and can be retrieved by calling \c QWidget::windowHandle() afterwards.
+ We override \c QWidget::showEvent() for this purpose:
+
+ \snippet musicplayer/musicplayer.cpp 7
+
+ The playback progress is wired directly to the taskbar progress indicator
+ by using signals and slots.
\snippet musicplayer/musicplayer.cpp 5
diff --git a/examples/winextras/musicplayer/musicplayer.cpp b/examples/winextras/musicplayer/musicplayer.cpp
index 12c6854..2ecff56 100644
--- a/examples/winextras/musicplayer/musicplayer.cpp
+++ b/examples/winextras/musicplayer/musicplayer.cpp
@@ -140,6 +140,18 @@ bool MusicPlayer::event(QEvent *event)
}
//! [0]
+//! [7]
+void MusicPlayer::showEvent(QShowEvent *event)
+{
+ QWidget::showEvent(event);
+ if (!taskbarButton->window()) {
+ auto window = windowHandle();
+ taskbarButton->setWindow(window);
+ thumbnailToolBar->setWindow(window);
+ }
+}
+//! [7]
+
static bool canHandleDrop(const QDropEvent *event)
{
const QList<QUrl> urls = event->mimeData()->urls();
@@ -383,7 +395,6 @@ void MusicPlayer::createJumpList()
void MusicPlayer::createTaskbar()
{
taskbarButton = new QWinTaskbarButton(this);
- taskbarButton->setWindow(windowHandle());
taskbarProgress = taskbarButton->progress();
connect(positionSlider, &QAbstractSlider::valueChanged, taskbarProgress, &QWinTaskbarProgress::setValue);
@@ -397,7 +408,6 @@ void MusicPlayer::createTaskbar()
void MusicPlayer::createThumbnailToolBar()
{
thumbnailToolBar = new QWinThumbnailToolBar(this);
- thumbnailToolBar->setWindow(windowHandle());
playToolButton = new QWinThumbnailToolButton(thumbnailToolBar);
playToolButton->setEnabled(false);
diff --git a/examples/winextras/musicplayer/musicplayer.h b/examples/winextras/musicplayer/musicplayer.h
index 56f4c67..49dd25b 100644
--- a/examples/winextras/musicplayer/musicplayer.h
+++ b/examples/winextras/musicplayer/musicplayer.h
@@ -82,6 +82,7 @@ public slots:
protected:
bool event(QEvent *event) override;
+ void showEvent(QShowEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;