当前位置: 首页>>代码示例>>C++>>正文


C++ QTabBar::setMovable方法代码示例

本文整理汇总了C++中QTabBar::setMovable方法的典型用法代码示例。如果您正苦于以下问题:C++ QTabBar::setMovable方法的具体用法?C++ QTabBar::setMovable怎么用?C++ QTabBar::setMovable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTabBar的用法示例。


在下文中一共展示了QTabBar::setMovable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QMainWindow

JKGStudio::JKGStudio(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui.setupUi(this);
	
	QToolBar *bar = addToolBar("Standard");
	bar->setFloatable(false);
	bar->setIconSize(QSize(16,16));
	
	QToolButton *newBtn = new QToolButton(this);
	newBtn->setMenu(ui.menuNew);
	newBtn->setIcon(QIcon(":/icons/new.png"));
	newBtn->setPopupMode(QToolButton::InstantPopup);
	newBtn->setText("New");

	ui.menuNew->menuAction()->setIcon(QIcon(":/icons/new.png"));

	bar->addWidget(newBtn);

	bar->addAction(ui.actionOpen);
	bar->addAction(ui.actionSave);
	bar->addSeparator();
	bar->addAction(ui.actionCut);
	bar->addAction(ui.actionCopy);
	bar->addAction(ui.actionPaste);
	bar->addSeparator();
	bar->addAction(ui.actionUndo);
	bar->addAction(ui.actionRedo);

	// Setup menu list
	setupMenuList();
	setupExtCommands();

	m_mdi = ui.mdiArea;

	// Create window menu
	QtWindowListMenu *windowList = new QtWindowListMenu(this);
	windowList->standardAction(QtWindowListMenu::CloseAction)->setIcon(QIcon(":/icons/close.png"));
	windowList->standardAction(QtWindowListMenu::CloseAllAction)->setIcon(QIcon(":/icons/closeall.png"));
	windowList->standardAction(QtWindowListMenu::TileAction)->setIcon(QIcon(":/icons/tile.png"));
	windowList->standardAction(QtWindowListMenu::CascadeAction)->setIcon(QIcon(":/icons/cascade.png"));
	windowList->standardAction(QtWindowListMenu::NextAction)->setIcon(QIcon(":/icons/next.png"));
	windowList->standardAction(QtWindowListMenu::PrevAction)->setIcon(QIcon(":/icons/prev.png"));
	
	windowList->attachToMdiArea(m_mdi);
	menuBar()->insertMenu(ui.menuAbout->menuAction(), windowList);

	
	this->setCentralWidget(m_mdi);

	QTabBar *tabbar = m_mdi->findChild<QTabBar *>();
	if (tabbar)
		tabbar->setExpanding(false);
	
	tabbar->setTabsClosable(true);
	connect(tabbar, SIGNAL(tabCloseRequested(int)), this, SLOT(onClose(void)));
	tabbar->setMovable(true);

	delete ui.centralWidget;

	QDockWidget *propdock = new QDockWidget("Properties", this);
	m_propbrowser = new QtTreePropertyBrowser(this);
	m_propmanager = new PropertyManager(m_propbrowser, this);

	propdock->toggleViewAction()->setIcon(QIcon(":/icons/properties.png"));
	propdock->setWidget(m_propbrowser);
	addDockWidget(Qt::RightDockWidgetArea, propdock);

	QDockWidget *undodock = new QDockWidget("Undo History", this);
	m_undoview = new QUndoView(this);

	//propdock->toggleViewAction()->setIcon(QIcon(":/icons/properties.png"));
	undodock->setWidget(m_undoview);
	addDockWidget(Qt::RightDockWidgetArea, undodock);

	QAction *sep = new QAction(this);
	sep->setSeparator(true);

	windowList->insertAction(windowList->actions().at(0), sep);
	windowList->insertAction(windowList->actions().at(0), undodock->toggleViewAction());
	windowList->insertAction(windowList->actions().at(0), propdock->toggleViewAction());
	
	MdiInterface::initialize(m_mdi, m_menuList, m_propmanager, m_undoview);
	m_interface = MdiInterface::get();

	onSubWindowActivated();
}
开发者ID:Lrns123,项目名称:JKG-Tools,代码行数:87,代码来源:jkgstudio.cpp

示例2: main

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    auto *proxyStyle = new TabBarProxyStyle;
    app.setStyle(proxyStyle);

    QWidget widget;
    QStackedWidget stackedWidget;
    QTabBar tabBar;
    tabBar.setDocumentMode(true);
    tabBar.setTabsClosable(true);
    tabBar.setMovable(true);
    tabBar.setExpanding(false);

    // top
    tabBar.setShape(QTabBar::RoundedNorth);
    // bottom
//    tabBar.setShape(QTabBar::RoundedSouth);
    // left
//    tabBar.setShape(QTabBar::RoundedWest);
    // right
//    tabBar.setShape(QTabBar::RoundedEast);

    const auto shortLabel = QStringLiteral("Tab %1");
    const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1");

    QMap<int, QWidget*> tabs;
    for (int i = 0; i < TabCount; i++) {
        QString tabNumberString = QString::number(i);
        QLabel *label = new QLabel(QStringLiteral("Tab %1 content").arg(tabNumberString));
        tabs[i] = label;
        label->setAlignment(Qt::AlignCenter);
        stackedWidget.addWidget(label);
        tabBar.addTab(shortLabel.arg(tabNumberString));
    }

    QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) {
        QWidget *thisWidget = tabs[from];
        QWidget *thatWidget = tabs[to];
        tabs[from] = thatWidget;
        tabs[to] = thisWidget;
    });

    QObject::connect(&tabBar, &QTabBar::currentChanged, [&stackedWidget, &tabs](int index) {
        if (index >= 0)
            stackedWidget.setCurrentWidget(tabs[index]);
    });

    QObject::connect(&tabBar, &QTabBar::tabCloseRequested, [&stackedWidget, &tabBar, &tabs](int index) {
        QWidget *widget = tabs[index];
        tabBar.removeTab(index);
        for (int i = index + 1; i < TabCount; i++)
            tabs[i-1] = tabs[i];
        int currentIndex = tabBar.currentIndex();
        if (currentIndex >= 0)
            stackedWidget.setCurrentWidget(tabs[currentIndex]);
        delete widget;
    });

    QLayout *layout;
    switch (tabBar.shape()) {
    case QTabBar::RoundedEast:
    case QTabBar::TriangularEast:
        tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
        layout = new QHBoxLayout(&widget);
        layout->addWidget(&stackedWidget);
        layout->addWidget(&tabBar);
        break;
    case QTabBar::RoundedWest:
    case QTabBar::TriangularWest:
        tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
        layout = new QHBoxLayout(&widget);
        layout->addWidget(&tabBar);
        layout->addWidget(&stackedWidget);
        break;
    case QTabBar::RoundedNorth:
    case QTabBar::TriangularNorth:
        tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        layout = new QVBoxLayout(&widget);
        layout->addWidget(&tabBar);
        layout->addWidget(&stackedWidget);
        break;
    case QTabBar::RoundedSouth:
    case QTabBar::TriangularSouth:
        tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
        layout = new QVBoxLayout(&widget);
        layout->addWidget(&stackedWidget);
        layout->addWidget(&tabBar);
        break;
    }

    TabBarForm form;
    layout->addWidget(&form);
    layout->setAlignment(&form, Qt::AlignHCenter);

    form.ui->documentModeButton->setChecked(tabBar.documentMode());
    QObject::connect(form.ui->documentModeButton, &QCheckBox::toggled, [&] {
        tabBar.setDocumentMode(form.ui->documentModeButton->isChecked());
        // QMacStyle (and maybe other styles) requires a re-polish to get the right font
        QApplication::sendEvent(&tabBar, new QEvent(QEvent::ThemeChange));
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的QTabBar::setMovable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。