Label set_markup

Hi there, @gwillems

Actually this topic is related to the Gnome Issue#5900
I have text like this:

cText += "|                                                                                                     |\n";
cText += "|Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa   |\n";
cText += "|    1  2  3  4  5  6 00                1  2  3 04                   1  2 08       1  2  3  4  5  6 13|\n";

When this text is set to the Label through set_markup it’s looks awkward

So I have no idea how come… 3 lines with the same width are printed in wrong way

Here an example is written in c++


#pragma once

#include <gtkmm/applicationwindow.h>
#include <gtkmm/label.h>
#include <gtkmm/box.h>

class testWin : public Gtk::ApplicationWindow {

  void onMap(GdkEventAny*);

  Gtk::Label lLabel,cLabel,rLabel;
  Gtk::Box box;
  Glib::ustring cText;


#pragma once

#include <gtkmm/application.h>
#include "testWin.hpp"

class testApp : public Gtk::Application {
  // Signals
  void on_activate() override;

  static Glib::RefPtr<Gtk::Application> create();

  testWin* createAppWin();


#include "testApp.hpp"

testApp::testApp() :
  Gtk::Application("org.gtkmm.examples.application") {

Glib::RefPtr<Gtk::Application> testApp::create() {
  static Glib::RefPtr<Gtk::Application> app{new testApp()};
  return app;

void testApp::on_activate()
  // The application has been started, so let's show a window.
  auto appWin{createAppWin()};

testWin* testApp::createAppWin() {
  auto appWin{new testWin()};

  appWin->signal_hide().connect([appWin](){ delete appWin; });

  return appWin;


#include "testWin.hpp"

: Gtk::ApplicationWindow(),
  lLabel{"Left Label"},
  cLabel{"Center Label"},
  rLabel{"Right Label"},


  bool tf{false};

  this->set_title("test app");
  this->set_name("test app");
  this->set_size_request(1908, 39);
  cText += "|                                                                                                     |\n";
  cText += "|Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa   |\n";
  cText += "|    1  2  3  4  5  6 00                1  2  3 04                   1  2 08       1  2  3  4  5  6 13|\n";


  this->signal_map_event().connect_notify(sigc::mem_fun(*this, &testWin::onMap));

void testWin::onMap(GdkEventAny*) {


#include "testApp.hpp"

int main(int argc, char* argv[]) {
  auto app{testApp::create()};

  return app->run(argc, argv);

Are you sure the font your app is using is monospace? The characters wont have a uniform size if it isnt.

Even when I’m using <span font-family=‘’> it doesn’t work

My apologies. With <span font-family=‘monospace’> works correct.
Thank you @HighKingofMelons

@HighKingofMelons even set_markup with monospace works correct, here the problem with set_tooltip_markup

Seems like there isnt enough horizontal space so the end of each line flows into a new one.

Is there a particular reason you are trying to squeeze a whole calender into a tooltip?

In the current example I’m using the same variable labelTxt which is used for both method set_markup and set_label_markup without any differences . So it’s strange set_markup works great wheres set_tooltip_markup is not. And at least means that both API are working in a different way

The reason: in Waybar we have clock module which can print month/year calendar for user purposes. Waybar Issue#2240 So user complains that if they set more than 2-3 columns(where each column is repesented by the separate Month) tooltip with the calendar is looking awkward

So temporary I switched tooltip for the Label to custom tooltip widget with TextView which solved the problem. But to me it seems not so performant solution … due to I have to set tooltip widget each signal time.

I see.

It does seem that the label that is built into GtkTooltip indeed has been set to have a max width of 50. Which does at least make sense for it’s primary purpose as a tooltip.

I can’t at a glance identify a better current solution than the one you have already. Though i think you might be overestimating the performance impact a little bit.

It migth be good to open an issue about letting you specify the width of the label in the tooltip though.

No, it’s not a good idea.

Don’t use a tooltip.

If you want to display something more complex than a simple line of text, you should have your own GtkPopover with a custom content.

1 Like

Thank you both, @ebassi and @HighKingofMelons . Let me check GtkPopover.

You can probably close the issue you linked, since it’s expected behavior.