Exemple #1
0
void tst_QTabBar::setUsesScrollButtons()
{
    QFETCH(int, usesArrows);
    QTabBar tabBar;
    if (usesArrows != -128)
        tabBar.setUsesScrollButtons(usesArrows);
    QTEST(tabBar.usesScrollButtons(), "expectedArrows");

    // Make sure style sheet does not override user set mode
    tabBar.setStyleSheet("QWidget { background-color: #ABA8A6;}");
    QTEST(tabBar.usesScrollButtons(), "expectedArrows");
}
Exemple #2
0
void tst_QTabBar::sizeHints()
{
    QTabBar tabBar;
	QSKIP("To be fixed on Mac (font size below not large enough) and Linux QWS (probably too large for the screen).", SkipSingle);
    tabBar.setFont(QFont("Arial", 10));
    tabBar.addTab("tab 01");
    tabBar.addTab("tab 02");
    tabBar.addTab("tab 03");
    tabBar.addTab("tab 04");
    tabBar.addTab("tab 05");
    tabBar.addTab("tab 06");
    tabBar.addTab("This is tab7");
    tabBar.addTab("This is tab8");
    tabBar.addTab("This is tab9 with a very long title");

    // No eliding and no scrolling -> tabbar becomes very wide
    tabBar.setUsesScrollButtons(false);
    tabBar.setElideMode(Qt::ElideNone);
//    qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint();
    QVERIFY(tabBar.minimumSizeHint().width() > 700);
    QVERIFY(tabBar.sizeHint().width() > 700);

    // Scrolling enabled -> no reason to become very wide
    tabBar.setUsesScrollButtons(true);
 //   qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint();
    QVERIFY(tabBar.minimumSizeHint().width() < 200);
    QVERIFY(tabBar.sizeHint().width() > 700); // unchanged

    // Eliding enabled -> no reason to become very wide
    tabBar.setUsesScrollButtons(false);
    tabBar.setElideMode(Qt::ElideRight);
//    qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint();
    QVERIFY(tabBar.minimumSizeHint().width() < 500);
    QVERIFY(tabBar.sizeHint().width() > 700); // unchanged

    tabBar.addTab("This is tab10 with a very long title");
    QVERIFY(tabBar.minimumSizeHint().width() < 600);
    QVERIFY(tabBar.sizeHint().width() > 700); // unchanged
}
void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
                                bool fancy) {
  QTabBar* bar = new QTabBar(this);
  bar->setShape(shape);
  bar->setDocumentMode(true);
  bar->setUsesScrollButtons(true);
  bar->setElideMode(Qt::ElideRight);

  if (shape == QTabBar::RoundedWest) {
    bar->setIconSize(QSize(22, 22));
  }

  if (fancy) {
    bar->setStyle(proxy_style_.get());
  }

  if (shape == QTabBar::RoundedNorth)
    top_layout_->insertWidget(0, bar);
  else
    side_layout_->insertWidget(0, bar);

  foreach (const Item& item, items_) {
    if (item.type_ != Item::Type_Tab)
      continue;

    QString label = item.tab_label_;
    if (shape == QTabBar::RoundedWest) {
      label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
    }

    int tab_id = -1;
    if (icons && text)
      tab_id = bar->addTab(item.tab_icon_, label);
    else if (icons)
      tab_id = bar->addTab(item.tab_icon_, QString());
    else if (text)
      tab_id = bar->addTab(label);

    // Adds tooltips only in Tabs mode or IconOnlyTabs mode
    // TODO in tab mode, show only if not elided, complicated since this doesn't inherit from QTabWidget
    if (shape == QTabBar::RoundedNorth && ((!text && icons) || (text && !icons)))
      bar->setTabToolTip(tab_id, item.tab_label_);
  }

  bar->setCurrentIndex(stack_->currentIndex());
  connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int)));
  tab_bar_ = bar;
}
void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
                                bool fancy) {
  QTabBar* bar = new QTabBar(this);
  bar->setShape(shape);
  bar->setDocumentMode(true);
  bar->setUsesScrollButtons(true);

  if (shape == QTabBar::RoundedWest) {
    bar->setIconSize(QSize(22, 22));
  }

  if (fancy) {
    bar->setStyle(proxy_style_.data());
  }

  if (shape == QTabBar::RoundedNorth)
    top_layout_->insertWidget(0, bar);
  else
    side_layout_->insertWidget(0, bar);

  foreach (const Item& item, items_) {
    if (item.type_ != Item::Type_Tab)
      continue;

    QString label = item.tab_label_;
    if (shape == QTabBar::RoundedWest) {
      label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
    }

    int tab_id = -1;
    if (icons && text)
      tab_id = bar->addTab(item.tab_icon_, label);
    else if (icons)
      tab_id = bar->addTab(item.tab_icon_, QString());
    else if (text)
      tab_id = bar->addTab(label);

    bar->setTabToolTip(tab_id, item.tab_label_);
  }

  bar->setCurrentIndex(stack_->currentIndex());
  connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int)));
  tab_bar_ = bar;
}
Exemple #5
0
int main (int argc, char *argv[])
{
  QApplication::setApplicationName ("KvantumViewer");
  QApplication viewer (argc,argv);
#if QT_VERSION >= 0x050500
  viewer.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif

  QStringList langs (QLocale::system().uiLanguages());
  QString lang; // bcp47Name() doesn't work under vbox
  if (!langs.isEmpty())
      lang = langs.first().replace ('-', '_');
  QTranslator qtTranslator;
  if (!qtTranslator.load ("qt_" + lang, QLibraryInfo::location (QLibraryInfo::TranslationsPath)))
  { // not needed; doesn't happen
      if (!langs.isEmpty())
      {
          lang = langs.first().split (QLatin1Char ('-')).first();
          qtTranslator.load ("qt_" + lang, QLibraryInfo::location (QLibraryInfo::TranslationsPath));
      }
  }
  viewer.installTranslator (&qtTranslator);

  QTranslator KPTranslator;
  KPTranslator.load ("kvantumpreview_" + lang, QStringLiteral (DATADIR) + "/kvantumpreview/translations");
  viewer.installTranslator (&KPTranslator);

  KvantumPreview k (NULL);
  k.show();
  QList<QTabWidget *> list = k.findChildren<QTabWidget*>();
  if (!list.isEmpty())
  {
    QTabWidget *tw = list.at (0);
#if QT_VERSION < 0x050000
    QTabBar *tb = tw->findChild<QTabBar*>(QLatin1String("qt_tabwidget_tabbar"));
    if (tb) tb->setUsesScrollButtons (true);
#else
    tw->tabBar()->setUsesScrollButtons (true);
#endif
  }
  QObject::connect (&viewer, &QApplication::lastWindowClosed, &viewer, &QApplication::quit);
  return viewer.exec();
}