StackedWidget not visible in DockWidget
-
Qt 6
Windows 11
C++
Qt Creator
Qt Widgets ProjectI have a dockWidget, and in the dockWidget is a stackWidget. The stackWidget has 4 pages, and each page has several buttons. When I run the app none of the page buttons are visible. I've tried putting the stackWidget directly into the dockWidget, and placing the stackWidget into a vertical layout which is in the dockWidget. Not sure what I'm doing wrong.
Bob K. -
Hi,
Please show the code you use.
The basic pattern with QDockWidget is along the line of:
QWidget *widget = new QWidget; // Add what you need to it QDockWidget *dockWidget = new QDockWidget; dockWidget->setWidget(widget);
-
I'm using Qt Creator.
Here's the ui code:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1000</width> <height>650</height> </rect> </property> <property name="minimumSize"> <size> <width>1000</width> <height>650</height> </size> </property> <property name="windowTitle"> <string>EES Photography</string> </property> <property name="windowIcon"> <iconset resource="resources.qrc"> <normaloff>:/img/images/EES.ico</normaloff>:/img/images/EES.ico</iconset> </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> <widget class="QTabWidget" name="tabWidgetData"> <property name="tabShape"> <enum>QTabWidget::Rounded</enum> </property> <property name="currentIndex"> <number>0</number> </property> <property name="tabBarAutoHide"> <bool>false</bool> </property> <widget class="QWidget" name="tabSession"> <attribute name="title"> <string>Session</string> </attribute> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> <layout class="QHBoxLayout" name="horizontalLayout_7"> <item> <layout class="QVBoxLayout" name="verticalLayout"> <item> <layout class="QHBoxLayout" name="horizontalLayout_5"> <item> <widget class="QLabel" name="labelIdentifier"> <property name="minimumSize"> <size> <width>80</width> <height>0</height> </size> </property> <property name="text"> <string>Identifier</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEditIdentifier"/> </item> </layout> </item> <item> <layout class="QFormLayout" name="formLayout_4"> <item row="0" column="0"> <widget class="QLabel" name="labelSessionType"> <property name="minimumSize"> <size> <width>80</width> <height>0</height> </size> </property> <property name="text"> <string>Session Type</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="0" column="1"> <widget class="QComboBox" name="comboBoxSessionType"/> </item> </layout> </item> </layout> </item> <item> <layout class="QVBoxLayout" name="verticalLayout_3"> <item> <layout class="QHBoxLayout" name="horizontalLayout_6"> <item> <widget class="QLabel" name="labelCamera"> <property name="minimumSize"> <size> <width>60</width> <height>0</height> </size> </property> <property name="text"> <string>Camera</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEdit_2"/> </item> </layout> </item> <item> <layout class="QFormLayout" name="formLayout_5"> <item row="0" column="0"> <widget class="QLabel" name="labelDate"> <property name="minimumSize"> <size> <width>60</width> <height>0</height> </size> </property> <property name="text"> <string>Date</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> </widget> </item> <item row="0" column="1"> <widget class="QDateTimeEdit" name="dateTimeEdit"/> </item> </layout> </item> </layout> </item> </layout> </item> <item> <widget class="QTabWidget" name="tabWidget"> <property name="currentIndex"> <number>0</number> </property> <widget class="QWidget" name="tab_9"> <attribute name="title"> <string>Analog</string> </attribute> </widget> <widget class="QWidget" name="tab_10"> <attribute name="title"> <string>Digital</string> </attribute> </widget> <widget class="QWidget" name="tab_11"> <attribute name="title"> <string>Contact Sheet</string> </attribute> </widget> </widget> </item> <item> <widget class="QLabel" name="labelNotes"> <property name="text"> <string>Notes</string> </property> </widget> </item> <item> <widget class="QPlainTextEdit" name="plainTextEdit"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="maximumSize"> <size> <width>16777215</width> <height>60</height> </size> </property> </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> <widget class="QPushButton" name="pushButtonSave"> <property name="text"> <string>Save</string> </property> </widget> </item> <item> <widget class="QPushButton" name="pushButtonDelete"> <property name="text"> <string>Delete</string> </property> </widget> </item> <item> <widget class="QPushButton" name="pushButtonCancel"> <property name="text"> <string>Cancel</string> </property> </widget> </item> </layout> </item> </layout> </widget> <widget class="QWidget" name="tabExposure"> <attribute name="title"> <string>Exposure</string> </attribute> </widget> <widget class="QWidget" name="tabOutput"> <attribute name="title"> <string>Output</string> </attribute> </widget> <widget class="QWidget" name="tabSearch"> <attribute name="title"> <string>Search</string> </attribute> </widget> </widget> </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>1000</width> <height>26</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>File</string> </property> <addaction name="actionExit"/> </widget> <widget class="QMenu" name="menuExit"> <property name="title"> <string>Edit</string> </property> <addaction name="actionCut"/> <addaction name="actionCopy"/> <addaction name="actionPaste"/> </widget> <widget class="QMenu" name="menuHelp"> <property name="title"> <string>Help</string> </property> <addaction name="actionAbout"/> </widget> <addaction name="menuFile"/> <addaction name="menuExit"/> <addaction name="menuHelp"/> </widget> <widget class="QStatusBar" name="statusbar"/> <widget class="QDockWidget" name="dockWidgetLookup"> <property name="minimumSize"> <size> <width>422</width> <height>500</height> </size> </property> <property name="features"> <set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set> </property> <property name="allowedAreas"> <set>Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea</set> </property> <attribute name="dockWidgetArea"> <number>1</number> </attribute> <widget class="QWidget" name="dockWidgetContents"> <property name="focusPolicy"> <enum>Qt::NoFocus</enum> </property> <layout class="QVBoxLayout" name="verticalLayout_5"> <item> <widget class="QStackedWidget" name="stackedWidget"> <property name="autoFillBackground"> <bool>true</bool> </property> <property name="frameShape"> <enum>QFrame::NoFrame</enum> </property> <property name="currentIndex"> <number>3</number> </property> <widget class="QWidget" name="pageOutput"> <property name="autoFillBackground"> <bool>true</bool> </property> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <widget class="QPushButton" name="pushButton_3"> <property name="text"> <string>PushButton</string> </property> </widget> </item> </layout> </widget> <widget class="QWidget" name="pageExosure"> <property name="autoFillBackground"> <bool>true</bool> </property> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QPushButton" name="pushButton_2"> <property name="text"> <string>PushButton</string> </property> </widget> </item> </layout> </widget> <widget class="QWidget" name="pageSearch"> <property name="autoFillBackground"> <bool>true</bool> </property> <layout class="QVBoxLayout" name="verticalLayout_6"> <item> <widget class="QPushButton" name="pushButton_4"> <property name="text"> <string>PushButton</string> </property> </widget> </item> </layout> </widget> <widget class="QWidget" name="pageSession"> <property name="autoFillBackground"> <bool>true</bool> </property> <layout class="QVBoxLayout" name="verticalLayout_8"> <item> <layout class="QHBoxLayout" name="horizontalLayout_9"> <item> <widget class="QPushButton" name="pushButtonClear_2"> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string>Clear</string> </property> </widget> </item> <item> <widget class="QLineEdit" name="lineEditSearch_2"/> </item> <item> <widget class="QPushButton" name="pushButtonSearch_2"> <property name="maximumSize"> <size> <width>100</width> <height>16777215</height> </size> </property> <property name="text"> <string>Search</string> </property> </widget> </item> </layout> </item> <item> <layout class="QVBoxLayout" name="verticalLayout_7"> <item> <widget class="QLabel" name="labelSession"> <property name="text"> <string>Session</string> </property> </widget> </item> <item> <widget class="QTableWidget" name="tableWidgetSessioLookup_2"/> </item> <item> <widget class="QPushButton" name="pushButton"> <property name="text"> <string>PushButton</string> </property> </widget> </item> </layout> </item> </layout> </widget> </widget> </item> </layout> </widget> </widget> <action name="actionExit"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/img/images/Exit.png</normaloff>:/img/images/Exit.png</iconset> </property> <property name="text"> <string>Exit</string> </property> </action> <action name="actionCut"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/img/images/Cut.png</normaloff>:/img/images/Cut.png</iconset> </property> <property name="text"> <string>Cut</string> </property> </action> <action name="actionCopy"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/img/images/Copy.png</normaloff>:/img/images/Copy.png</iconset> </property> <property name="text"> <string>Copy</string> </property> </action> <action name="actionPaste"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/img/images/Paste.png</normaloff>:/img/images/Paste.png</iconset> </property> <property name="text"> <string>Paste</string> </property> </action> <action name="actionAbout"> <property name="icon"> <iconset resource="resources.qrc"> <normaloff>:/img/images/AboutBox.png</normaloff>:/img/images/AboutBox.png</iconset> </property> <property name="text"> <string>About</string> </property> </action> </widget> <tabstops> <tabstop>lineEditIdentifier</tabstop> <tabstop>comboBoxSessionType</tabstop> <tabstop>lineEdit_2</tabstop> <tabstop>dateTimeEdit</tabstop> <tabstop>tabWidget</tabstop> <tabstop>plainTextEdit</tabstop> <tabstop>pushButtonSave</tabstop> <tabstop>pushButtonDelete</tabstop> <tabstop>pushButtonCancel</tabstop> </tabstops> <resources> <include location="resources.qrc"/> </resources> <connections/>
</ui>
-
Are you sure it's not your stacked widget that is showing the wrong widget ?
That said, I would split that QMainWindow in smaller widgets to improve encapsulation.
-
The stacked widget is not displaying any widgets.
I'm not sure what you mean by splitting the main window into smaller widgets? The main window contains a tab widget, which is where all the data will be displayed.
The dock widget contains a list of database entries. Once an entry is selected, any data manipulation will take place in the tab widget. That's why I wanted dock widget to be moveable.
-
-
Qt Creator System Information, one more time...
{noformat}
Qt 6.3.1 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows"
OS: Windows 11 Version 2009 [winnt version 10.0.22621]Architecture: x86_64; features: SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 AVX AVX2
Environment:
QtMsBuild="C:\Users\rkama\AppData\Local\QtMsBuild"Features: QT_NO_EXCEPTIONS
Library info:
PrefixPath: C:\Qt\Tools\QtCreator\bin
DocumentationPath: C:\Qt\Tools\QtCreator\bin\doc
HeadersPath: C:\Qt\Tools\QtCreator\bin\include
LibrariesPath: C:\Qt\Tools\QtCreator\bin
LibraryExecutablesPath: C:\Qt\Tools\QtCreator\bin\bin
BinariesPath: C:\Qt\Tools\QtCreator\bin
PluginsPath: C:\Qt\Tools\QtCreator\bin\plugins
QmlImportsPath: C:\Qt\Tools\QtCreator\bin\qml
ArchDataPath: C:\Qt\Tools\QtCreator\bin
DataPath: C:\Qt\Tools\QtCreator\bin
TranslationsPath: C:\Qt\Tools\QtCreator\bin\translations
ExamplesPath: C:\Qt\Tools\QtCreator\bin\examples
TestsPath: C:\Qt\Tools\QtCreator\bin\tests
SettingsPath:Standard paths [... denote writable entry]:
DesktopLocation: "Desktop" C:\Users\rkama\OneDrive\Desktop
DocumentsLocation: "Documents" C:\Users\rkama\OneDrive\Documents
FontsLocation: "Fonts" C:\WINDOWS\Fonts
ApplicationsLocation: "Applications" C:\Users\rkama\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
MusicLocation: "Music" C:\Users\rkama\Music
MoviesLocation: "Movies" C:\Users\rkama\Videos
PicturesLocation: "Pictures" C:\Users\rkama\OneDrive\Pictures
TempLocation: "Temporary Directory" C:\Users\rkama\AppData\Local\Temp
HomeLocation: "Home" C:\Users\rkama
AppLocalDataLocation: "Application Data" C:\Users\rkama\AppData\Local\QtProject\qtdiag C:\ProgramData\QtProject\qtdiag C:\Qt\Tools\QtCreator\bin C:\Qt\Tools\QtCreator\bin\data C:\Qt\Tools\QtCreator\bin\data\QtProject\qtdiag
CacheLocation: "Cache" C:\Users\rkama\AppData\Local\QtProject\qtdiag\cache
GenericDataLocation: "Shared Data" C:\Users\rkama\AppData\Local C:\ProgramData C:\Qt\Tools\QtCreator\bin C:\Qt\Tools\QtCreator\bin\data
RuntimeLocation: "Runtime" C:\Users\rkama
ConfigLocation: "Configuration" C:\Users\rkama\AppData\Local\QtProject\qtdiag C:\ProgramData\QtProject\qtdiag C:\Qt\Tools\QtCreator\bin C:\Qt\Tools\QtCreator\bin\data C:\Qt\Tools\QtCreator\bin\data\QtProject\qtdiag
DownloadLocation: "Download" C:\Users\rkama\Downloads
GenericCacheLocation: "Shared Cache" C:\Users\rkama\AppData\Local\cache
GenericConfigLocation: "Shared Configuration" C:\Users\rkama\AppData\Local C:\ProgramData C:\Qt\Tools\QtCreator\bin C:\Qt\Tools\QtCreator\bin\data
AppDataLocation: "Application Configuration" C:\Users\rkama\AppData\Roaming\QtProject\qtdiag C:\ProgramData\QtProject\qtdiag C:\Qt\Tools\QtCreator\bin C:\Qt\Tools\QtCreator\bin\data C:\Qt\Tools\QtCreator\bin\data\QtProject\qtdiag
AppConfigLocation: "Application Configuration" C:\Users\rkama\AppData\Local\QtProject\qtdiag C:\ProgramData\QtProject\qtdiag C:\Qt\Tools\QtCreator\bin C:\Qt\Tools\QtCreator\bin\data C:\Qt\Tools\QtCreator\bin\data\QtProject\qtdiagFile selectors (increasing order of precedence):
en_US windows winntNetwork:
Using "OpenSSL 1.1.1d 10 Sep 2019", version: 0x1010104fPlatform capabilities: ThreadedPixmaps OpenGL ThreadedOpenGL WindowMasks MultipleWindows ForeignWindows NonFullScreenWindows NativeWidgets WindowManagement RasterGLSurface AllGLFunctionsQueryable
Style hints:
mouseDoubleClickInterval: 500
mousePressAndHoldInterval: 800
startDragDistance: 10
startDragTime: 500
startDragVelocity: 0
keyboardInputInterval: 400
keyboardAutoRepeatRate: 32
cursorFlashTime: 1060
showIsFullScreen: 0
showIsMaximized: 0
passwordMaskDelay: 0
passwordMaskCharacter: U+000
Plugin information:- Android 8.0.1
- AutoTest 8.0.1
AutotoolsProjectManager 8.0.1
BareMetal 8.0.1 - Bazaar 8.0.1
Beautifier 8.0.1 - BinEditor 8.0.1
- Bookmarks 8.0.1
Boot2Qt 8.0.1 - CMakeProjectManager 8.0.1
- CVS 8.0.1
- ClangCodeModel 8.0.1
ClangFormat 8.0.1 - ClangTools 8.0.1
- ClassView 8.0.1
ClearCase 8.0.1
Coco 8.0.1 - CodePaster 8.0.1
CompilationDatabaseProjectManager 8.0.1
Conan 8.0.1 - Core 8.0.1
- CppEditor 8.0.1
Cppcheck 8.0.1 - CtfVisualizer 8.0.1
- Debugger 8.0.1
- Designer 8.0.1
- DiffEditor 8.0.1
Docker 8.0.1
EmacsKeys 8.0.1 - FakeVim 8.0.1
- GLSLEditor 8.0.1
- GenericProjectManager 8.0.1
- Git 8.0.1
GitLab 8.0.1
HelloWorld 8.0.1 - Help 8.0.1
- ImageViewer 8.0.1
- IncrediBuild 8.0.1
Ios 8.0.1 - LanguageClient 8.0.1
- LicenseChecker 8.0.1
- Macros 8.0.1
- Marketplace 8.0.1
McuSupport 8.0.1 - Mercurial 8.0.1
MesonProjectManager 8.0.1 - ModelEditor 8.0.1
Nim 8.0.1 - PerfProfiler 8.0.1
Perforce 8.0.1 - ProjectExplorer 8.0.1
- Python 8.0.1
- QbsProjectManager 8.0.1
- QmakeProjectManager 8.0.1
QmlDesigner 8.0.1 - QmlJSEditor 8.0.1
- QmlJSTools 8.0.1
- QmlPreview 8.0.1
- QmlProfiler 8.0.1
- QmlProjectManager 8.0.1
- Qnx 8.0.1
- QtSupport 8.0.1
- RemoteLinux 8.0.1
- ResourceEditor 8.0.1
- ScxmlEditor 8.0.1
SerialTerminal 8.0.1
SilverSearcher 8.0.1
StudioWelcome 8.0.1 - Subversion 8.0.1
- TaskList 8.0.1
- TextEditor 8.0.1
Todo 8.0.1 - UpdateInfo 8.0.1
- UsageStatistic 8.0.1
- Valgrind 8.0.1
- VcsBase 8.0.1
Vxworks 8.0.1
WebAssembly 8.0.1 - Welcome 8.0.1
Used settingspath: ~/AppData/Roaming/QtProject
Qt Creator 8.0.1
Based on Qt 6.3.1 (MSVC 2019, x86_64)
From revision 9c963ce8ae
Built on Aug 11 2022 01:13:43{noformat}