本文整理汇总了C++中QDockWidget::widget方法的典型用法代码示例。如果您正苦于以下问题:C++ QDockWidget::widget方法的具体用法?C++ QDockWidget::widget怎么用?C++ QDockWidget::widget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDockWidget
的用法示例。
在下文中一共展示了QDockWidget::widget方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeHint
void tst_QDockWidget::task169808_setFloating()
{
//we try to test if the sizeHint of the dock widget widget is taken into account
class MyWidget : public QWidget
{
public:
QSize sizeHint() const
{
const QRect& deskRect = qApp->desktop()->availableGeometry();
return QSize(qMin(300, deskRect.width() / 2), qMin(300, deskRect.height() / 2));
}
QSize minimumSizeHint() const
{
return QSize(20,20);
}
void paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(rect(), Qt::red);
}
};
QMainWindow mw;
mw.setCentralWidget(new MyWidget);
QDockWidget *dw = new QDockWidget("my dock");
dw->setWidget(new MyWidget);
mw.addDockWidget(Qt::LeftDockWidgetArea, dw);
dw->setFloating(true);
mw.show();
QVERIFY(QTest::qWaitForWindowExposed(&mw));
QCOMPARE(dw->widget()->size(), dw->widget()->sizeHint());
//and now we try to test if the contents margin is taken into account
dw->widget()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
dw->setFloating(false);
QVERIFY(QTest::qWaitForWindowExposed(&mw));
qApp->processEvents(); //leave time processing events
const QSize oldSize = dw->size();
const int margin = 20;
dw->setContentsMargins(margin, margin, margin, margin);
QVERIFY(QTest::qWaitForWindowExposed(&mw));
qApp->processEvents(); //leave time processing events
//widget size shouldn't have changed
QCOMPARE(dw->widget()->size(), dw->widget()->sizeHint());
//dockwidget should be bigger
QCOMPARE(dw->size(), oldSize + QSize(margin * 2, margin * 2));
}
示例2: createDockWidget
QDockWidget* MainWindow::createDockWidget(KoDockFactoryBase* factory)
{
QDockWidget* dockWidget = 0;
if(!m_dockWidgetMap.contains(factory->id())) {
dockWidget = factory->createDockWidget();
// It is quite possible that a dock factory cannot create the dock; don't
// do anything in that case.
if(!dockWidget) return 0;
m_dockWidgets.push_back(dockWidget);
dockWidget->setObjectName(factory->id());
dockWidget->setParent(this);
if(dockWidget->widget() && dockWidget->widget()->layout())
dockWidget->widget()->layout()->setContentsMargins(1, 1, 1, 1);
Qt::DockWidgetArea side = Qt::RightDockWidgetArea;
bool visible = true;
switch(factory->defaultDockPosition()) {
case KoDockFactoryBase::DockTornOff:
dockWidget->setFloating(true); // position nicely?
break;
case KoDockFactoryBase::DockTop:
side = Qt::TopDockWidgetArea; break;
case KoDockFactoryBase::DockLeft:
side = Qt::LeftDockWidgetArea; break;
case KoDockFactoryBase::DockBottom:
side = Qt::BottomDockWidgetArea; break;
case KoDockFactoryBase::DockRight:
side = Qt::RightDockWidgetArea; break;
case KoDockFactoryBase::DockMinimized:
visible = false; break;
default:;
}
addDockWidget(side, dockWidget);
if(dockWidget->features() & QDockWidget::DockWidgetClosable) {
m_dockWidgetMenu->addAction(dockWidget->toggleViewAction());
if(!visible)
dockWidget->hide();
}
m_dockWidgetMap.insert(factory->id(), dockWidget);
} else {
dockWidget = m_dockWidgetMap[ factory->id()];
}
connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(forceDockTabFonts()));
return dockWidget;
}
示例3: kisIcon
void KoDockWidgetTitleBar::Private::toggleCollapsed()
{
QDockWidget *q = qobject_cast<QDockWidget*>(thePublic->parentWidget());
if (q == 0) // there does not *have* to be anything on the dockwidget.
return;
preCollapsedWidth = q->widget()->isHidden() ? -1 : thePublic->width();
q->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); // will be overwritten again next
if (q->widget()) {
q->widget()->setVisible(q->widget()->isHidden());
collapseButton->setIcon(q->widget()->isHidden() ? kisIcon("docker_collapse_b") : kisIcon("docker_collapse_a"));
}
}
示例4: workspaceWidgetActivated
void GCF::Components::MainWindow::addChildWidget(QWidget* parent, QWidget* child)
{
if(!parent || !child)
return;
if(parent == d->workspace)
{
d->workspace->addTab(child, child->windowTitle());
child->installEventFilter(this);
child->setAutoFillBackground(true);
emit workspaceWidgetActivated(d->workspace->currentWidget());
}
else
{
QList<QDockWidget*> dockWidgets = d->dockWidgetMap.values();
QDockWidget* dw = qobject_cast<QDockWidget*>(parent);
if(dw && dockWidgets.contains(dw))
{
QTabWidget* tw = qobject_cast<QTabWidget*>(dw->widget());
tw->addTab(child, child->windowTitle());
child->setAutoFillBackground(true);
if(tw->count())
dw->show();
else
dw->hide();
}
}
}
示例5:
void GCF::Components::MainWindow::removeChildWidget(QWidget* parent, QWidget* child)
{
if(!parent || !child)
return;
if(parent == d->workspace)
{
d->workspace->removeTab(d->workspace->indexOf(child));
child->removeEventFilter(this);
}
else
{
QList<QDockWidget*> dockWidgets = d->dockWidgetMap.values();
QDockWidget* dw = qobject_cast<QDockWidget*>(parent);
if(dw && dockWidgets.contains(dw))
{
QTabWidget* tw = qobject_cast<QTabWidget*>(dw->widget());
tw->removeTab(tw->indexOf(child));
if(tw->count())
dw->show();
else
dw->hide();
}
}
}
示例6: closeProject
void PogadeMainWindow::closeProject() {
//TODO: finish it
QListIterator<QDockWidget*> i(_dockSourceEditorList);
while (i.hasNext()) {
PogadeSourceCodeEditor* w = (PogadeSourceCodeEditor*) i.next()->widget();
bool saveall = false;
//TODO: check changed and ask user
if(w->fileChanged()) {
if(saveall) {
w->saveFile();
}
else {
QMessageBox msgBox;
msgBox.setText(tr("The File %1 revision %2 ( %3 ) has been modified and not saved").arg(w->sourceFile()->name()).arg(w->sourceFile()->getRevInUse()).arg(w->sourceFile()->getRevisionName(w->sourceFile()->getRevInUse())));
msgBox.setInformativeText(tr("Do you want to save your changes before changing revision?"));
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::SaveAll);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::SaveAll:
saveall = true;
case QMessageBox::Save:
w->saveFile();
break;
case QMessageBox::Discard:
break;
case QMessageBox::Cancel:
return;
break;
default:
// should never be reached
break;
}
}
}
}
//TODO: clean the project stuff
_dockProjectViewer->setVisible(false);
delete _dockProjectViewer->widget();
delete _dockProjectViewer;
_dockProjectViewer = nullptr;
while(!_dockSourceEditorList.isEmpty()) {
QDockWidget* dock = _dockSourceEditorList.takeFirst();
dock->setVisible(false);
PogadeSourceCodeEditor* w = (PogadeSourceCodeEditor*) dock->widget();
delete w;
}
_dockSourceEditorList.clear();
_allCorrect = true;
_validProject = false;
delete _project;
_project = nullptr;
this->setUpProject();
}
示例7: removeDockWindow
/**
* Removes the specified dock window with name \name without deleting it.
*/
QWidget* DockWindowManager::removeDockWindow(const char* name)
{
QWidget* widget=0;
for (QList<QDockWidget*>::Iterator it = d->_dockedWindows.begin(); it != d->_dockedWindows.end(); ++it) {
if ((*it)->objectName() == QLatin1String(name)) {
QDockWidget* dw = *it;
d->_dockedWindows.erase(it);
getMainWindow()->removeDockWidget(dw);
// avoid to destruct the embedded widget
widget = dw->widget();
widget->setParent(0);
dw->setWidget(0);
disconnect(dw, SIGNAL(destroyed(QObject*)),
this, SLOT(onDockWidgetDestroyed(QObject*)));
disconnect(widget, SIGNAL(destroyed(QObject*)),
this, SLOT(onWidgetDestroyed(QObject*)));
delete dw; // destruct the QDockWidget, i.e. the parent of the widget
break;
}
}
示例8: setUIMode
void MainWindow::setUIMode(bool docks_enabled)
{
// Already in this mode?
if(docks_enabled == ui->tabWidget->isHidden())
return;
settings->setValue("docksEnabled", docks_enabled);
// Enabling tabs needs a restart
if(!docks_enabled)
{
QMessageBox::warning(this, trUtf8("Restart needed"), trUtf8("You need to restart firebird to enable the tab interface."));
return;
}
//Convert the tabs into QDockWidgets
QDockWidget *last_dock = nullptr;
while(ui->tabWidget->count())
{
QWidget *tab = ui->tabWidget->widget(0);
QDockWidget *dw = new QDockWidget(ui->tabWidget->tabText(0), this);
docks.push_back(dw);
#ifdef Q_OS_MAC
connect(dw, SIGNAL(visibilityChanged(bool)), this, SLOT(dockVisibilityChanged(bool)));
#endif
if(tab == ui->tabDebugger)
dock_debugger = dw;
dw->setObjectName(ui->tabWidget->tabText(0));
tab->setParent(dw->widget());
addDockWidget(Qt::RightDockWidgetArea, dw);
dw->setWidget(tab);
if(last_dock != nullptr)
tabifyDockWidget(last_dock, dw);
last_dock = dw;
}
ui->tabWidget->setHidden(true);
ui->uiDocks->setChecked(docks_enabled);
}
示例9: QDockWidget
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_inspectorUi(new Ui::InspectorConsoleDock()),
m_entityUi (new Ui::InspectorEntityDock()),
m_mediaUi (new Ui::InspectorMediaDock()),
m_texturesUi (new Ui::InspectorTexturesDock()),
m_cameraUi (new Ui::CameraWindow())
{
ui->setupUi(this);
// setup docks
QDockWidget *inspectorConsoleDock = new QDockWidget(tr("Console"), this);
QDockWidget *inspectorEntityDock = new QDockWidget(tr("Entity"), this);
QDockWidget *inspectorMediaDock = new QDockWidget(tr("Media"), this);
QDockWidget *inspectorTexturesDock = new QDockWidget(tr("Textures"), this);
QDockWidget *cameraWindow = new QDockWidget(tr("Cam"), this);
inspectorConsoleDock->setObjectName("inspectorConsoleDock");
inspectorEntityDock->setObjectName("inspectorEntityDock");
inspectorMediaDock->setObjectName("inspectorMediaDock");
inspectorTexturesDock->setObjectName("inspectorTexturesDock");
cameraWindow->setObjectName("cameraWindow");
inspectorConsoleDock->setWidget(new QWidget(inspectorConsoleDock));
inspectorEntityDock->setWidget(new QWidget(inspectorEntityDock));
inspectorMediaDock->setWidget(new QWidget(inspectorMediaDock));
inspectorTexturesDock->setWidget(new QWidget(inspectorTexturesDock));
cameraWindow->setWidget(new QWidget(cameraWindow));
m_inspectorUi->setupUi(inspectorConsoleDock->widget());
m_entityUi->setupUi(inspectorEntityDock->widget());
m_mediaUi->setupUi(inspectorMediaDock->widget());
m_texturesUi->setupUi(inspectorTexturesDock->widget());
m_cameraUi->setupUi(cameraWindow->widget());
addDockWidget(Qt::LeftDockWidgetArea, cameraWindow);
addDockWidget(Qt::LeftDockWidgetArea, inspectorConsoleDock);
addDockWidget(Qt::LeftDockWidgetArea, inspectorEntityDock);
addDockWidget(Qt::LeftDockWidgetArea, inspectorMediaDock);
addDockWidget(Qt::LeftDockWidgetArea, inspectorTexturesDock);
m_docks.append(cameraWindow);
m_docks.append(inspectorConsoleDock);
m_docks.append(inspectorEntityDock);
m_docks.append(inspectorMediaDock);
m_docks.append(inspectorTexturesDock);
tabifyDockWidget(inspectorConsoleDock, inspectorEntityDock);
tabifyDockWidget(inspectorEntityDock, inspectorMediaDock);
tabifyDockWidget(inspectorMediaDock, inspectorTexturesDock);
// setup icons from theme (on linux) or use resource icon
ui->actionNewMap->setIcon(QIcon::fromTheme("document-new", QIcon(":/icons/new")));
ui->actionOpen-> setIcon(QIcon::fromTheme("document-open", QIcon(":/icons/open")));
ui->actionSave-> setIcon(QIcon::fromTheme("document-save", QIcon(":/icons/save")));
ui->actionExit-> setIcon(QIcon::fromTheme("application-exit", QIcon(":/icons/exit")));
ui->actionCut-> setIcon(QIcon::fromTheme("edit-cut", QIcon(":/icons/cut")));
ui->actionCopy-> setIcon(QIcon::fromTheme("edit-copy", QIcon(":/icons/copy")));
ui->actionPaste-> setIcon(QIcon::fromTheme("edit-paste", QIcon(":/icons/paste")));
ui->actionDelete-> setIcon(QIcon::fromTheme("edit-delete", QIcon(":/icons/delete")));
ui->actionPreferences->setIcon(QIcon::fromTheme("preferences-system", QIcon(":/icons/preferences")));
// setup statusbar widgets
statusCoords = new QLabel("x: 0.0\ty: 0.0\tz: 0.0");
ui->statusBar->addPermanentWidget(statusCoords);
}
示例10: handle_dockVisibilityChanged
void WidgetLoggerEngineFrontend::handle_dockVisibilityChanged(bool visible) {
QDockWidget* dock = qobject_cast<QDockWidget*> (sender());
if (dock && visible) {
MessagesPlainTextEditTab* front_end = qobject_cast<MessagesPlainTextEditTab*> (dock->widget());
if (front_end) {
CONTEXT_MANAGER->setNewContext(front_end->contextString(),true);
}
}
}
示例11: sizeHint
QSize KoDockWidgetTitleBar::sizeHint() const
{
if (isHidden()) {
return QSize(0, 0);
}
QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget());
int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q);
// get size of buttons...
QSize closeSize(0, 0);
if (d->closeButton && hasFeature(q, QDockWidget::DockWidgetClosable)) {
closeSize = d->closeButton->sizeHint();
}
QSize floatSize(0, 0);
if (d->floatButton && hasFeature(q, QDockWidget::DockWidgetFloatable)) {
floatSize = d->floatButton->sizeHint();
}
QSize hideSize(0, 0);
if (d->collapseButton && d->collapsable) {
hideSize = d->collapseButton->sizeHint();
}
QSize lockSize(0, 0);
if (d->lockButton && d->lockable) {
lockSize = d->lockButton->sizeHint();
}
int buttonHeight = qMax(qMax(qMax(closeSize.height(), floatSize.height()), hideSize.height()), lockSize.height()) + 2;
int buttonWidth = closeSize.width() + floatSize.width() + hideSize.width() + lockSize.width();
int height = buttonHeight;
if (d->textVisibilityMode == FullTextAlwaysVisible) {
// get font size
QFontMetrics titleFontMetrics = q->fontMetrics();
int fontHeight = titleFontMetrics.lineSpacing() + 2 * mw;
height = qMax(height, fontHeight);
}
/*
* Calculate the width of title and add to the total width of the docker window when collapsed.
*/
const int titleWidth =
(d->textVisibilityMode == FullTextAlwaysVisible) ? (q->fontMetrics().width(q->windowTitle()) + 2*mw) :
0;
if (d->preCollapsedWidth > 0) {
return QSize(d->preCollapsedWidth, height);
}
else {
if (d->textVisibilityMode == FullTextAlwaysVisible) {
return QSize(buttonWidth /*+ height*/ + 2*mw + 2*fw + titleWidth, height);
}
else {
if (q->widget()) {
return QSize(qMin(q->widget()->sizeHint().width(), buttonWidth), height);
}
else {
return QSize(buttonWidth, height);
}
}
}
}
示例12: createDockWidget
QDockWidget* MainWindow::createDockWidget(KoDockFactoryBase* factory)
{
QDockWidget* dockWidget = 0;
if(!m_dockWidgetMap.contains(factory->id())) {
dockWidget = factory->createDockWidget();
// It is quite possible that a dock factory cannot create the dock; don't
// do anything in that case.
if(!dockWidget) return 0;
m_dockWidgets.push_back(dockWidget);
dockWidget->setObjectName(factory->id());
dockWidget->setParent(this);
if(dockWidget->widget() && dockWidget->widget()->layout())
dockWidget->widget()->layout()->setContentsMargins(1, 1, 1, 1);
Qt::DockWidgetArea side = Qt::RightDockWidgetArea;
bool visible = true;
switch(factory->defaultDockPosition()) {
case KoDockFactoryBase::DockTornOff:
dockWidget->setFloating(true); // position nicely?
break;
case KoDockFactoryBase::DockTop:
side = Qt::TopDockWidgetArea; break;
case KoDockFactoryBase::DockLeft:
side = Qt::LeftDockWidgetArea; break;
case KoDockFactoryBase::DockBottom:
side = Qt::BottomDockWidgetArea; break;
case KoDockFactoryBase::DockRight:
side = Qt::RightDockWidgetArea; break;
case KoDockFactoryBase::DockMinimized:
visible = false; break;
default:;
}
addDockWidget(side, dockWidget);
if(dockWidget->features() & QDockWidget::DockWidgetClosable) {
m_dockWidgetMenu->addAction(dockWidget->toggleViewAction());
if(!visible)
dockWidget->hide();
}
m_dockWidgetMap.insert(factory->id(), dockWidget);
} else {
dockWidget = m_dockWidgetMap[ factory->id()];
}
KConfigGroup group(KSharedConfig::openConfig(), "GUI");
QFont dockWidgetFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75);
pointSize = qMax(pointSize, QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont).pointSizeF());
dockWidgetFont.setPointSizeF(pointSize);
#ifdef Q_WS_MAC
dockWidget->setAttribute(Qt::WA_MacSmallSize, true);
#endif
dockWidget->setFont(dockWidgetFont);
connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(forceDockTabFonts()));
return dockWidget;
}
示例13: setCollapsed
void KoDockWidgetTitleBar::setCollapsed(bool collapsed)
{
QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget());
if (q && q->widget() && q->widget()->isHidden() != collapsed)
d->toggleCollapsed();
}
示例14: widget
void tst_QDockWidget::widget()
{
{
QDockWidget dw;
QVERIFY(dw.widget() == 0);
}
{
QDockWidget dw;
QWidget *w1 = new QWidget;
QWidget *w2 = new QWidget;
dw.setWidget(w1);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w1);
QCOMPARE(w1->parentWidget(), (QWidget*)&dw);
dw.setWidget(0);
QVERIFY(dw.widget() == 0);
dw.setWidget(w2);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w2);
QCOMPARE(w2->parentWidget(), (QWidget*)&dw);
dw.setWidget(0);
QVERIFY(dw.widget() == 0);
dw.setWidget(w1);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w1);
QCOMPARE(w1->parentWidget(), (QWidget*)&dw);
dw.setWidget(w2);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w2);
QCOMPARE(w2->parentWidget(), (QWidget*)&dw);
dw.setWidget(0);
QVERIFY(dw.widget() == 0);
}
{
QDockWidget dw;
QWidget *w1 = new QWidget;
QWidget *w2 = new QWidget;
dw.setWidget(w1);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w1);
QCOMPARE(w1->parentWidget(), (QWidget*)&dw);
w1->setParent(0);
QVERIFY(dw.widget() == 0);
dw.setWidget(w2);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w2);
QCOMPARE(w2->parentWidget(), (QWidget*)&dw);
w2->setParent(0);
QVERIFY(dw.widget() == 0);
dw.setWidget(w1);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w1);
QCOMPARE(w1->parentWidget(), (QWidget*)&dw);
dw.setWidget(w2);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w2);
QCOMPARE(w2->parentWidget(), (QWidget*)&dw);
w1->setParent(0);
QVERIFY(dw.widget() != 0);
QVERIFY(dw.widget() == w2);
QCOMPARE(w2->parentWidget(), (QWidget*)&dw);
w2->setParent(0);
QVERIFY(dw.widget() == 0);
delete w1;
delete w2;
}
}