How can I:
1) properly set Gtk::Notebook in Gtk::HeaderBar like:
window.add(box);
2) implement autohide tabs ( animated like css transitions with scale(0) and scale(1) ) ?
My code:
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main app(argc, argv);
Gtk::Window window;
window.set_default_size(200, 200);
Gtk::HBox box;
Gtk::HeaderBar titlebar;
Gtk::Notebook notebook;
Gtk::TextView text;
notebook.append_page(text, "First");
box.pack_start(notebook);
titlebar.set_custom_title(box);
window.set_titlebar(titlebar);
window.show_all_children();
return app.run(window);
}
Related
Referring to this question.
After embedding an external application with the code:
#include <QApplication>
#include<QProcess>
#include<QDesktopServices>
#include<QUrl>
#include<QWindow>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow *w = new QMainWindow();
w->setWindowTitle("Genome Embedded Calculator");
QWindow* window = QWindow::fromWinId(41943047); // Hardcoded Window Id for Genome Calculator
window->setFlags(Qt::FramelessWindowHint);
QWidget *widget = QWidget::createWindowContainer(window);
w->setCentralWidget(widget);
w->show();
return a.exec();
}
How to detach the QWindow after closing the application?
I want the gnome-calculator process to continue working after closing my application.
With the following code I generate a window with buttons:
#include <QApplication>
#include <QtWidgets>
class Item : public QWidget {
QHBoxLayout hLayout{this};
QPushButton bt{"button"};
public:
Item() : QWidget() {
hLayout.addWidget(&bt);
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget w;
QVBoxLayout vLayout(&w);
vLayout.addWidget(new Item());
vLayout.addWidget(new Item());
vLayout.addWidget(new Item());
vLayout.addWidget(new Item());
vLayout.addWidget(new Item());
w.show();
return app.exec();
}
With layout.setContentsMargins(0,0,0,0) I can go to:
Is it possible to reduce even more space between buttons?
You can try using setSpacing method :
vLayout.setSpacing(0);
But I think the real issue here would be that your layout is stretched out to cover whole widget and it arranges layout items accordingly.
Another thing you can try is to set the margin :
vLayout.setMargin(0);
You can remove the space, by adjusting the spacing:
http://doc.qt.io/qt-5/qlayout.html#spacing-prop
Setting it to 0 should bring the widgets together.
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget w;
QVBoxLayout vLayout(&w);
vLayout.addWidget(new Item());
...
// Removes outer margins
vLayout.setContentsMargins(0,0,0,0);
// Set space between items to '0'
vLayout.setSpacing(0);
w.show();
return app.exec();
}
In your example above you should probably also add a strech section:
http://doc.qt.io/qt-5/qboxlayout.html#addStretch
Let's say we have a barebones QWebView:
#include <QApplication>
#include <QWebView>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QWebView view;
view.show();
view.setUrl(QUrl("http://google.com"));
return app.exec();
}
How can I display a graphic overlay, preferably fullscreen with transparency and minimal animation (like timer/beachball/etc.) from when the page starts loading till it's finished? Should also be triggered when url changes from within the QWebView.
You can use the LoadingOverlay class provided in this answer to draw an overlay over any QWidget. In your case, show the overlay on top of the QWebView when the signal loadStarted is triggered and hide it, when the signal loadFinished is triggered.
The following code should get you started. I put the code from the linked answer into overlay.h, the subclass of QWebView which handles the showing/hiding of the overlay is in webview.h:
webview.h
#include "overlay.h"
#include <QWebView>
class WebView : public QWebView
{
Q_OBJECT
public:
WebView(QWidget * parent) : QWebView(parent)
{
overlay = new LoadingOverlay(parent);
connect(this,SIGNAL(loadFinished(bool)),this,SLOT(hideOverlay()));
connect(this,SIGNAL(loadStarted()),this,SLOT(showOverlay()));
}
~WebView()
{
}
public slots:
void showOverlay()
{
overlay->show();
}
void hideOverlay()
{
overlay->hide();
}
private:
LoadingOverlay* overlay;
};
main.cpp
#include <QApplication>
#include "overlay.h"
#include "webview.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ContainerWidget base;
Webview w(&base);
base.show();
w.load(QUrl("http://google.com"));
return a.exec();
}
Here is the code
#include <QApplication>
#include <QtWebKitWidgets/QWebView>
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
QWebView view;
QCoreApplication::addLibraryPath("./plugins");
view.settings()->setAttribute(QWebSettings::PluginsEnabled, true);
// crash here
view.load(QUrl("http://hon.qq.com/act/20140320video/Aluna.html"));
// OK to show youtube
//view.load(QUrl("http://www.youtube.com/watch?v=KMU0tzLwhbE"));
view.show();
return app.exec();
}
It crashes when play video on hon.qq.com, but works well playing video on Youtube.
I want my notebook tab labels to be rotated by 90°.
I tried the set_angle() function of Gtk::Label but it doesn't work:
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window mainwindow;
Gtk::Notebook sidebar;
Gtk::Label tab;
mainwindow.add(sidebar);
sidebar.set_tab_pos(Gtk::POS_LEFT);
tab.set_angle(90);
sidebar.append_page(tab, "text");
sidebar.show();
tab.show();
Gtk::Main::run(mainwindow);
return 0;
}
It seems you are adding the label as the child widget. You don't have a widget to be the page child in your code, but if you did and named it "child", you'd have something like this:
sidebar.set_tab_pos(Gtk::POS_LEFT);
tab.set_angle(90);
tab.set_text("text");
sidebar.append_page(child, tab);