[gtkmm] Flickering TextView in ScrolledWindow
- From: Morten Brix Pedersen <morten wtf dk>
- To: gtkmm-list gnome org
- Subject: [gtkmm] Flickering TextView in ScrolledWindow
- Date: Tue, 9 Jul 2002 16:23:55 +0200
Hi,
I'm porting my application to gtkmm2, which means that I'm replacing
Gtk::Text with Gtk::TextView. However, the code used to scroll down
automatically flickers the screen.
It didn't happen when a Gtk::Text was used instead. Simple case below.
Thanks.
- Morten.
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/textview.h>
#include <gtkmm/textbuffer.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/box.h>
#include <gtkmm/main.h>
class AppWindow : public Gtk::Window
{
public:
AppWindow();
virtual ~AppWindow() { }
void insertText();
protected:
Gtk::TextView _textview;
Gtk::ScrolledWindow _swin;
Gtk::Button _button;
Gtk::VBox _vbox;
};
AppWindow::AppWindow()
: _button("Insert text")
{
set_default_size(600, 400);
_button.signal_clicked().connect(slot(*this, &AppWindow::insertText));
_swin.add(_textview);
_vbox.pack_start(_swin);
_vbox.pack_start(_button, Gtk::SHRINK);
add(_vbox);
show_all();
}
void AppWindow::insertText()
{
// see if the scrollbar is located in the bottom, then we need to scroll
// after insert
bool scroll = false;
if (_swin.get_vadjustment()->get_value() + _swin.get_vadjustment()->get_page_size() == _swin.get_vadjustment()->get_upper())
scroll = true;
// insert the text at the end
Gtk::TextIter iter = _textview.get_buffer()->get_end_iter();
_textview.get_buffer()->insert(iter, "Hello World - this is a test to see how inserted text flickers in the scrolledwindow!\n");
// finally scroll down; this causes the widget to flicker
if (scroll)
_swin.get_vadjustment()->set_value(_swin.get_vadjustment()->get_upper());
}
int main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
AppWindow window;
kit.run(window);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]