PDA

View Full Version : Unable to minize space b/n colored QWidget and size adjustment pane of QDockWidget



rawfool
28th November 2011, 04:07
I've created 2 QDockWidgets in MainWindow and added QWidget to each. I tried to color each of these widget with some color, but I find some space between size adjustment bar & color. What would be problem with this? Thank you.
7131

Code:

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QWidget>
#include <QHBoxLayout>
#include <QFrame>
#include <QPushButton>
#include <QTabWidget>
#include <QMenu>
#include <QAction>
#include <QDockWidget>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void baseLayerSettings(void);

private:
QFrame *baseLayer;
QWidget *headerWidget, *footerWidget;
QPushButton *tab1_Button1, *tab1_Button2, *tab2_Button1, *tab1_Button3, *startMenu_button;
QMenu *startMenu;
QAction *menuAction;
QDockWidget *headerDock, *centerDock, *footerDock;
QHBoxLayout *footerLayout;
};

MainWindow.cpp

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
baseLayerSettings();
setCentralWidget(baseLayer);

}

MainWindow::~MainWindow()
{

}

void MainWindow::baseLayerSettings(void)
{
headerDock = new QDockWidget(this);
headerDock->setMinimumHeight(70);
headerDock->setFeatures(QDockWidget::NoDockWidgetFeatures);
baseLayer = new QFrame(this);
baseLayer->setStyleSheet("background-color: rgba(245, 250, 250, 255);");
footerDock = new QDockWidget(this);
footerDock->setMinimumHeight(70);
footerDock->setFeatures(QDockWidget::NoDockWidgetFeatures);

this->setCentralWidget(baseLayer);
this->addDockWidget(Qt::TopDockWidgetArea, headerDock);
this->addDockWidget(Qt::BottomDockWidgetArea, footerDock);

startMenu = new QMenu;
startMenu->setStyleSheet("QMenu::item {padding: 1px 10px 1px 20px; background-color: rgba(245, 250, 250, 255); height: 35px;};");
startMenu->setStyleSheet("QMenu::item:selected { background-color: rgba(109, 146, 155, 255); }");
startMenu->addAction("Break-Shift");
startMenu->addAction("Logout");
startMenu->addAction("Shutdown");

startMenu_button = new QPushButton(tr("Menu"));
startMenu_button->setFixedSize(75, 40);
startMenu_button->setStyleSheet("border-style: outset; border-width: 1px; border-radius: 10px; border-color: blue; font-family: Monaco; font: 16px; color: rgba(4, 98, 148, 255); background-color: rgba(183, 175, 163, 255); min-width: 5em; min-height : 25px;");
startMenu_button->setStyleSheet("QPushButton:pressed { background-color: darkgray; font-family: Monaco; font-style: italic; color: rgba(29, 49, 122, 255)}");
startMenu_button->setMenu(startMenu);

headerWidget = new QWidget;
headerWidget->setStyleSheet("background-color: rgba(172, 209, 233, 255);");
headerDock->setWidget(headerWidget);
footerDock->setWidget(startMenu_button);

footerWidget = new QWidget;
footerWidget->setStyleSheet("background-color: rgba(232, 208, 169, 255);");
footerDock->setWidget(footerWidget);

footerLayout = new QHBoxLayout;
footerWidget->setLayout(footerLayout);
footerLayout->addWidget(startMenu_button, 0, Qt::AlignLeft | Qt::AlignBottom);
startMenu_button->show();

}

ChrisW67
28th November 2011, 04:51
That is the title bar of the dock widget.

If you want two vertical resizable but otherwise fixed panels at top and bottom then why not use a QSplitter?

rawfool
28th November 2011, 05:15
Hi Chris,
Thanks for your reply. Which widget can I add to splitter instead of QDockWidget ? Does normal QWidget solve my purpose?

ChrisW67
28th November 2011, 05:19
Any widget you like. QWidget is a generic empty container that you can use, but presumably you want something in these panels.

rawfool
28th November 2011, 06:42
Hi Chris,
Thanks again. I need some sort of help from you. On a mainwindow, I need 3 sections like header, body, footer. Each section contains some widgets like tabs, pushbuttons, labels, progressbars, etc. These widgets in each section changes according to the menu. Can u help me in choosing corresponding base widgets for each section. Thank you.

ChrisW67
28th November 2011, 07:20
For each panel that is not an out-of-the-box widget you create a HeaderWidget/BodyWidget/FooterWidget class derived from QWidget (or whatever). In the constructor you build the UI (sub-widgets and layout) that the widget should contain. That construction code would be the same as whatever you intended to be in the dock widgets.

In your main window constructor you create an object of each of the three widgets classes, and add them to a QSplitter and add that QSplitter to the main window layout to make your main UI.

All of that can be done with Designer or by hand coding. There are buckets of hand-coded examples in the documentation.