LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Blogs > rainbowsally
User Name
Password

Notices

Rate this Entry

A QT4 InfoBox w/ StaysOnTop, Gradients, And Some Other Junk

Posted 12-14-2012 at 04:04 AM by rainbowsally
Updated 08-06-2014 at 09:37 AM by rainbowsally

A QT4 InfoBox

Today's Features
  • An Info Box, callable the commandline or a shell program that has scrollbars and resizes depending on content.
  • Using some of the LQ-qt lib functions.
  • A gradient stylesheet. Open the ui file with Designer and take a peek at the stylesheet syntax.
  • A snippet to make a window stay on top.
  • A way to resize a form window depending on text width and height of a TextEdit widget.
  • Using grid layout to make a resizable window and using 'widgets' instead of expanders to keep certain things in proportion (namely the button position and icon).

[Note: The gradient syntax is in the TextEdit's style sheet, if that's all you need today. Just grab the infobox.ui file and open it in Designer.]

The widget uses 'Deja Vu Mono' for the font. Change that if you don't like it.

Here's a screenshot of the infobox stretched out to max for the Makefile created by mc2.

http://rainbowsally.org/rainbowsally...ox-800x600.png

The commandline was
Code:
InfoBox Makefile
For this build we can start with the ui file and the main file (see warning below) and build the whole thing (5 additional source files) with mc2 features.

Warning: Versions of mc2 < 3.0.12 may overwrite files you have made changes to. Get the latest mc2 version here
http://www.linuxquestions.org/questi...support-34783/
or keep a backup of app-main.cpp that I'll post here in a sec.

First, run the script to create the image file if you want the nice info icon.
Code:
sh create-icon.sh
Here's the file.

file: src/create-icon.sh
purpose: encode a png image file in the base64 text format
Code:
#!/bin/sh

###########################################################################
# This is a base64 extractor for info3.png needed by the InfoBox ui file.
# The resulting png should be exactly 
# $> du -cb info3.png
# 4255    info3.png
# 4255    total
###########################################################################

cat << _eof | base64 -d > info3.png
iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz
AAAG7AAABuwBHnU4NQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABAcSURB
VHja5VsLkBzFef56nvu8vad0p9MD6Y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woiygCmslTFEKKUB5lDNc7+mOopKioQgo1CSAGP9NFfcYWfsvbALo6BOBsdO
5usY8cYFaFyMRxRcdSIIqykAlelQVQ0qVWHxbbjh8h8mwSA2XMWF6zpw+baRKuBQDyf9EEXd0bgA
cy8OjwZJNi7A73Io+B2P/weGOqNIFUQrJAAAAABJRU5ErkJggg==
_eof
If this doesn't work, copy some other 'info-like' png file to the current directory and change it's name to info3.png so you don't have to change any other files.

And here's the qrc file that turns the png file into a resource.

file: src/infobox.qrc
purpose: source file
Code:
<RCC>
  <qresource prefix="images">
    <file>info3.png</file>
  </qresource>
</RCC>
And here's the ui file that creates the class files, which we won't have to modify at all for this simple app.


file: src/infobox.ui
purpose: source file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>InfoBox</class>
 <widget class="QWidget" name="InfoBox">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>464</width>
    <height>127</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Notice</string>
  </property>
  <layout class="QGridLayout" name="gridLayout">
   <item row="0" column="1" rowspan="2">
    <widget class="QTextEdit" name="Object">
     <property name="sizePolicy">
      <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
       <horstretch>0</horstretch>
       <verstretch>0</verstretch>
      </sizepolicy>
     </property>
     <property name="minimumSize">
      <size>
       <width>391</width>
       <height>65</height>
      </size>
     </property>
     <property name="font">
      <font>
       <family>DejaVu Sans Mono [unknown]</family>
       <pointsize>9</pointsize>
      </font>
     </property>
     <property name="styleSheet">
      <string notr="true">background:qlineargradient(spread:pad, x1:0.515, y1:1, x2:0.494845, y2:0.04, stop:0 #BEB7B4, stop:1 #DDD9D8)</string>
     </property>
     <property name="lineWrapMode">
      <enum>QTextEdit::NoWrap</enum>
     </property>
     <property name="readOnly">
      <bool>true</bool>
     </property>
    </widget>
   </item>
   <item row="2" column="0" colspan="2">
    <widget class="QFrame" name="frame">
     <property name="minimumSize">
      <size>
       <width>0</width>
       <height>50</height>
      </size>
     </property>
     <property name="maximumSize">
      <size>
       <width>16777215</width>
       <height>50</height>
      </size>
     </property>
     <property name="frameShape">
      <enum>QFrame::NoFrame</enum>
     </property>
     <property name="frameShadow">
      <enum>QFrame::Raised</enum>
     </property>
     <layout class="QGridLayout" name="gridLayout_2">
      <item row="0" column="0">
       <widget class="QWidget" name="widget" native="true">
        <property name="minimumSize">
         <size>
          <width>120</width>
          <height>20</height>
         </size>
        </property>
        <property name="maximumSize">
         <size>
          <width>120</width>
          <height>20</height>
         </size>
        </property>
        <widget class="QWidget" name="widget_2" native="true">
         <property name="geometry">
          <rect>
           <x>0</x>
           <y>0</y>
           <width>120</width>
           <height>20</height>
          </rect>
         </property>
         <property name="minimumSize">
          <size>
           <width>120</width>
           <height>20</height>
          </size>
         </property>
         <property name="maximumSize">
          <size>
           <width>120</width>
           <height>20</height>
          </size>
         </property>
        </widget>
       </widget>
      </item>
      <item row="0" column="1">
       <spacer name="horizontalSpacer">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>56</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item row="0" column="2">
       <widget class="QPushButton" name="butOk">
        <property name="minimumSize">
         <size>
          <width>102</width>
          <height>27</height>
         </size>
        </property>
        <property name="maximumSize">
         <size>
          <width>102</width>
          <height>27</height>
         </size>
        </property>
        <property name="text">
         <string>&amp;Ok</string>
        </property>
       </widget>
      </item>
      <item row="0" column="3">
       <spacer name="horizontalSpacer_2">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>46</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item row="0" column="4">
       <widget class="QWidget" name="widget_3" native="true">
        <property name="minimumSize">
         <size>
          <width>120</width>
          <height>20</height>
         </size>
        </property>
        <property name="maximumSize">
         <size>
          <width>120</width>
          <height>20</height>
         </size>
        </property>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
   <item row="0" column="0">
    <widget class="QLabel" name="label">
     <property name="minimumSize">
      <size>
       <width>61</width>
       <height>60</height>
      </size>
     </property>
     <property name="maximumSize">
      <size>
       <width>61</width>
       <height>60</height>
      </size>
     </property>
     <property name="styleSheet">
      <string notr="true"/>
     </property>
     <property name="text">
      <string/>
     </property>
     <property name="pixmap">
      <pixmap resource="infobox.qrc">:/images/info3.png</pixmap>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <resources>
  <include location="infobox.qrc"/>
 </resources>
 <connections>
  <connection>
   <sender>butOk</sender>
   <signal>clicked()</signal>
   <receiver>InfoBox</receiver>
   <slot>close()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>245</x>
     <y>99</y>
    </hint>
    <hint type="destinationlabel">
     <x>244</x>
     <y>143</y>
    </hint>
   </hints>
  </connection>
 </connections>
 <slots>
  <slot>toggleHide()</slot>
 </slots>
</ui>
And here's the baby you have to look out for if you have an older mc2 version. Keep a backup of this one or copy it into your source folder after you run mc2 (see below). This one also contains all the interestig stuff. :-)


file: src/app-main.cpp
purpose: source file
Code:
#include <stdio.h> // stderr
#include <QApplication>
#include <QEvent> // not used
#include <QScrollBar>
#include "infobox.h"
#include "ui_infobox.h" // the inner fields
#include <LQ-qt/filename.h>
#include <LQ-qt/qt4-utils.h>

void dbg(){}

void lqSetStaysOnTop(QWidget* w);

int usage(int errcode);
int main(int argc, char *argv[])
{
  dbg();
  
  // this sets the global qApp instance
  new QApplication (argc, argv);  
  
  // help or filename only.
  if((argc < 2) || (argc > 2))
    return usage(1);
  if(strcmp(argv[1], "--help") == 0)
    return usage(0);
  
  //////////////////////////////////////////////
  // load the text to display
  char* buf;
  size_t buflen;
  const char* infofile = argv[1];
  filename_load(infofile, &buf, &buflen);
  if(!buflen)
    return 1; // silently, but deadly ;-)
  
  InfoBox w;
  
  w.ui->Object->setPlainText(buf);
  // TODO: set a good size for display  
  
  lqSetStaysOnTop(&w);
  w.show();
  
  // adjustSize(Infobox* self, int maxw, int maxh)
  { 
    // must have window flags set and show() must be done
    // before we come here.
    
    // let the queue run to get it all set up so far
    qApp->processEvents(); 
    
    // now using the window itself to tell us the text extents
    // both horiz and vert, adjust the size to maxw and maxh
    
    // we could read the desktop geometry and areas set aside for
    // taskbars, etc., but not for this version.
    
    int maxw = 700;
    int maxh = 550;
    
    // locate the widgets we need to modify
    QTextEdit* ed = w.ui->Object;
    QScrollBar* hsb = ed->horizontalScrollBar();
    QScrollBar* vsb = ed->verticalScrollBar();    
    QWidget* form = (QWidget*)ed->parent();
    
    // init
    int width = form->width();
    int height = form->height();
    
    while(1) {
      int changed = 0;
      if(hsb->isVisible()) {
        //QWidget(1,1,1,1,1);
        if(width < maxw) {
          width += 8;
          changed ++;
        }
        else
          width = maxw;
      }
      if(vsb->isVisible()) {
        if(height < maxh) {
          height += 8;
          changed++;
        }
        else
          height = maxh;
      }
      if(changed)
        form->resize(width, height);
      else
        break;
    } // while
  }
  
  lqCenterWindow(qApp, &w); // in libLQ-qt
  return qApp->exec();
}

int usage(int errcode)
{
  const char* usage_str =
      "Usage: InfoBox <infoFile> | --help\n"
      "  Shows a box that stays on top of the window stack\n"
      "  with scrollbars to display information in <infoFile>\n\n";
  
  if(errcode)
    fprintf(stderr, usage_str);
  else
    printf(usage_str);
  return errcode;
}

void lqSetStaysOnTop(QWidget* w)
{
  w->setWindowFlags(Qt::WindowStaysOnTopHint);
}

And here's the mc2 definitions file which goes above the src dir to create the Makefile and as you'll see, quite a bit of other stuff as well.

DO NOT USE THE update-ui TARGET WITH AN OLDER MC2. It will clobber your app-main.cpp file.


file: mc2.def
purpose: source file
Code:
# mc2.def template created with Makefile Creator 'mc2'

# change main to *.so for a lib or plugin
OUTNAME = InfoBox

PREFIX = $(HOME)/usr32

# Optionally include global or semi-global defs for your makefile here.
# include ../makeinclude # typical location for a PROJECT makeinclude
                         # if the current makefile is under a PROJECT

# my debug versions of all the QT libs are currently here
QT_DBGLIB = -L/opt/qt4/lib


# Note: the *DIR, COMPILE and LINK defs can't join lines due to the way 
# they are imported from the environment but user defined variables will 
# accept the backslash to join lines to create vertical lists.  See the 
# HDR and OBJ lists in the generated Makefile for example.

## The directories for sources, (temp) objects, and binary output(s)
## (single lines for BINDIR, SRCDIR, OBJDIR)
BINDIR = .
SRCDIR = src
OBJDIR = o

# example list of additional flags for a plugin. multi-line = ok.
DEFINES = \
  -D_REENTRANT \
  -DQT_QT3SUPPORT_LIB \
  -DQT3_SUPPORT \
  -DQT_GUI_LIB \
  -DQT_CORE_LIB \
  ###############
  
#  -DQT_SHARED \
#  -DQT_PLUGIN \
#  ##############


## What COMPILE should do. 
## (single lines for COMPILE, CFLAGS, INCLUDE)
COMPILE = g++ -c 

#CFLAGS = $(DEFINES) -Wall -W -g3 # debug
CFLAGS = $(DEFINES) -Wall -W -O2 # release
  # add -fPIC and -D_REENTRANT to the DEFINES list for shared libs and plugins
  # change -O2 to -g3 for debug versions
  
INCLUDE = -I$(PREFIX)/include -I$(SRCDIR) -I/usr/include -I/usr/include/Qt -I/usr/include/QtGui -I /usr/include/QtCore 

# add these as needed to the includes above.  
# -I /usr/include/Qt             -I /usr/include/QtHelp         -I /usr/include/QtSvg
# -I /usr/include/Qt3Support     -I /usr/include/QtMultimedia   -I /usr/include/QtTest
# -I /usr/include/QtCore         -I /usr/include/QtNetwork      -I /usr/include/QtUiTools
# -I /usr/include/QtDBus         -I /usr/include/QtOpenGL       -I /usr/include/QtWebKit
# -I /usr/include/QtDeclarative  -I /usr/include/QtScript       -I /usr/include/QtXml
# -I /usr/include/QtDesigner     -I /usr/include/QtScriptTools  -I /usr/include/QtXmlPatterns
# -I /usr/include/QtGui          -I /usr/include/QtSql

# If you have lots of them and want to join lines (i.e., '\') list them under 
# DEFINES similar to the way HDR or OBJ defs look in the Makefile and add $(DEFINES)
# to the CFLAGS


## What LINK should do. 
## (single lines for LINK, LDFLAGS, LIB)
LINK = g++ 
LDFLAGS =  -lLQ-qt -lQtGui -lQtCore 

# add as needed. see notes for DEFINES and INCLUDES above if you need to split lines
# -lQt3Support              -lQtNetwork               -lQtCLucene
# -lQtOpenGL                -lQtCore                  -lQtScript
# -lQtDBus                  -lQtScriptTools           -lQtDeclarative
# -lQtSql                   -lQtDesignerComponents    -lQtSvg
# -lQtDesigner              -lQtTest                  -lQtGui 
# -lQtWebKit                -lQtHelp                  -lQtXmlPatterns
# -lQtMultimedia            -lQtXml


# adjust the LIB paths for your system.  Try 'locate libQtGui'
# to find the right path for your system.
LIB = -L$(PREFIX)/lib -L/usr/lib 

################################################################
## User Defined Targets

clean: 
  @rm -f $(MAIN)
  @rm -f $(OBJ)
  @rm -f *~ */*~ */*/*~ */*/*/*~


# example
MOC_INCLUDE = -I $(SRCDIR)

ui: force # 'force:' is a noop target to force execution
  uic src/infobox.ui -o src/ui_infobox.h
  moc src/infobox.h -o src/moc_infobox.cpp
  rcc src/infobox.qrc -o src/qrc_infobox.cpp
  mc2 -update # add new files to the makefile
  echo "This is just a flag for the makefile" > src/ui_done

clean-ui: force # 'force:' is a noop target to force execution
  rm -f src/ui_*.h src/moc_*.cpp src/qrc_*.cpp
  rm -f src/moc_*.o src/qrc_*.o

src/ui_done:
  @make ui  
  @echo "Rebuilding ui files..."
  @echo "Pls repeat previous operation to continue"
  @exit 1

update-ui:
  @echo "WARNING: This may overwrite existing files with changes"
  @echo "in them with versions of mc2 < 3.0.12"
  @echo "Backup your files now if you need to or Ctrl-C to abort"
  @read key
  @mc2 -create qt4-files src/infobox.ui
  @make ui

force: # used to force execution

Ok. We now have four files. We need to create a few more.

run
Code:
mc2 -create qt4-files src/infobox.ui
You will see a list of targets you can import into your mc2.def file if you need to. You don't need to. They are already there.

We now have four new files.

Run
Code:
mc2 -init
to create the Makefile

And now we can just use make for the rest.

Code:
make ui
And now we have one more new file, not counting 'ui_done' which is just a makefile flag.

If you want to edit the ui file with QT Designer, use
Code:
make update-ui
but be aware that this is likely to mess up your app-main if you don't have a newer version of mc2.

But anyway... type
Code:
make
And now you have an InfoBox like this one (1024x768 resolution for this one so it might appear a bit large on some screens).

http://rainbowsally.org/rainbowsally.../infobox-2.png

Notice the gradient is more obvious when the text file isn't so large.

- The Computer Mad Science Team

:-)
Posted in Uncategorized
Views 623 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 05:26 PM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration