Skip to content

Instantly share code, notes, and snippets.

@maxi3390
Created March 21, 2015 14:57
Show Gist options
  • Save maxi3390/ee9a614bfde6ad1f5157 to your computer and use it in GitHub Desktop.
Save maxi3390/ee9a614bfde6ad1f5157 to your computer and use it in GitHub Desktop.
Testing GTK and CSS with C++
/* Compile with
* g++ -o program main.cpp `pkg-config --cflags --libs gtkmm-3.0`
*
* Original source: http://www.taringa.net/posts/linux/18386145/Gtkmm-3-12-c-subclass-o-class-dependiente.html
*/
#include <iostream>
#include <gtkmm-3.0/gtkmm.h>
#include <gdkmm/general.h>
#include <gtkmm/widget.h>
#include <gtkmm/cssprovider.h>
#include <cstring>
class MyLabel : public Gtk::Button{
public :
MyLabel(){
set_border_width(10);
add_label("tu");
}
};
int main (int argc, char *argv[]){
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Box *vbox = new Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
window.add(*vbox);
Gtk::Button button;
button.add_label("Question");
vbox->pack_start(button, Gtk::PACK_SHRINK, 0);
Gtk::Label label("Hola");
vbox->pack_start(label, Gtk::PACK_SHRINK, 0);
Gtk::Entry entry;
vbox->pack_start(entry, Gtk::PACK_SHRINK, 0);
MyLabel mylabel;
vbox->pack_start(mylabel, Gtk::PACK_EXPAND_WIDGET, 0);
/**********/
//load css
Glib::RefPtr<Gtk::CssProvider> cssProvider = Gtk::CssProvider::create();
cssProvider->load_from_path("style.css");
Glib::RefPtr<Gtk::StyleContext> styleContext = Gtk::StyleContext::create();
//get default screen
Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
//add provider for screen in all application
styleContext->add_provider_for_screen(screen, cssProvider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
window.show_all();
Gtk::Main::run(window);
return EXIT_SUCCESS;
}
MyLabel {
border-radius: 30px;
border-color: shade(#CCCCCC, 0.95);
}
.button {
color: #C71EFF;
-GtkWidget-focus-padding: 1;
-GtkWidget-focus-line-width: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment