Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.7k Posts
  • [SOLVED] Windows Event Log Management

    6
    0 Votes
    6 Posts
    7k Views
    H
    OpenEventLog and ReadEventLog is what i meant. I wrote very simple code for testing and it's worked. Thanks a lot (: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363672(v=vs.85).aspx
  • [SOLVED] Problem clicking on QTableView

    3
    0 Votes
    3 Posts
    3k Views
    P
    [SOLVED] The problem was with the sentence setEditStrategy(QSqlTableModel::OnFieldChange), in the constructor of the class derived from QSqlTableModel. That sentence made QTableView to repopulate and scroll to top after editing a cell. To circumvent the problem I need to replace the previous sentence with setEditStrategy(QSqlTableModel::OnManualSubmit), and call submitAll() when I finish editing the table. I was going mad :-)
  • Add AnalogClock widget into BoxLayout

    5
    0 Votes
    5 Posts
    4k Views
    G
    You can see the analog clock once you enlarge the window manually. The cause for the "invisible" clock is that it does not provide a size hint. Add this to your clock class and it works as expected: @ // in the header file: public: QSize sizeHint() const; // in the implementation: QSize AnalogClock::sizeHint() const { return QSize(100, 100); } @ Just another hint, your hLayout and vLayout is not neede, it is sufficient to put all your widgets into the main layout like this: @ mainLayout->addWidget(label); mainLayout->addWidget(clock); mainLayout->addWidget(dial); @
  • SetWidgetResizable(true)

    3
    0 Votes
    3 Posts
    4k Views
    S
    Thank you! That worked like a charm.
  • [SOLVED] Gettings all group names using QSettings..?

    4
    0 Votes
    4 Posts
    10k Views
    V
    Thanks! Worked great!
  • QFileDialog::getOpenFileName target

    3
    0 Votes
    3 Posts
    3k Views
    A
    The docs are quite clear... The third argument of getOpenFileName is the standard path.
  • QTextEdit question

    11
    0 Votes
    11 Posts
    6k Views
    X
    Hello, I added this header: #include <private/qrrichtext_p.h> and it works. Many thanks again!!
  • QDateTime and Qt::ISODate

    9
    0 Votes
    9 Posts
    8k Views
    P
    Thanks for the answer, i understand.
  • 0 Votes
    3 Posts
    8k Views
    M
    Thanks Vass ...its working fine..
  • QFiles input with and without overwriting data

    3
    0 Votes
    3 Posts
    3k Views
    L
    Take a look at the various "OpenMode":http://doc.qt.nokia.com/latest/qiodevice.html#OpenModeFlag-enum flags. In addition, see "QFile::seek()":http://doc.qt.nokia.com/latest/qfile.html#seek and "QSeek:resize()":http://doc.qt.nokia.com/latest/qfile.html#resize.
  • Signal and slot related issue?

    7
    0 Votes
    7 Posts
    3k Views
    P
    @ Button::Button (QWidget *parent, QPixmap &pixmap1, QString tool_tip_text, char *btn_txt, bool erase_bkground, QRect rect, int num_states ) : QPushButton( parent), m_hovered(false), m_pressed(false), is_animate(false) { pixmap = pixmap1; button_width = rect.width (); button_height = rect.height(); num_of_states = num_states; num_of_images = pixmap.width()/button_width; press_count = 0; count = 0; link_flag = false; button_txt = btn_txt; tt_flag = true; tt_normal = tool_tip_text; timer = new QTimer(this); target = QRectF(0.0, 0.0, button_width, button_height); source = QRectF(0.0, 0.0, button_width, button_height); } Button::~Button () {} void Button::draw_button_normal() { this->m_pressed = false; m_hovered = false; //source = QRectF(0.0, 0.0, button_width, button_height); qDebug ()<<"normal"; if (this->is_animate) { timer->singleShot (5000, this, SLOT(mousePress ())); } else { timer->stop(); qDebug()<<"stop timer"; // source = QRectF(0.0, 0.0, button_width, button_height); } qDebug()<<"mouse press"<<this->m_pressed<<m_hovered; qDebug()<<this; this->repaint(); qDebug()<<this; } void Button::animate_button (bool is_animate) { this->is_animate = is_animate; if (this->is_animate) { timer->start (); mousePress (); qDebug ()<<"timer called"; } else { is_animate = false; draw_button_normal(); } qDebug()<<this<< "animate button"; // draw_button_normal (); } void Button::mousePress () { this->m_pressed = true; m_hovered = false; if(num_of_states == 2) { press_count++; } if (this->isEnabled ()) { source = QRectF((button_width) * 2.0, 0.0, button_width, button_height); } if(num_of_images == 4) { count++; source = QRectF(0.0, 0.0, button_width, button_height); } if (this->is_animate) { timer->singleShot (5000, this,SLOT(draw_button_normal())); qDebug ()<<"mousePress"; } this->repaint(); } void Button::paintEvent (QPaintEvent *e) { qDebug()<<"mpressed1"<<this->m_pressed<<m_hovered; Q_UNUSED(e); QPainter painter(this); painter.setRenderHint(QPainter::HighQualityAntialiasing); if (!pixmap.isNull ()) { this->resize(pixmap.width(), pixmap.height()); QRegion region(0,0,0,0); QImage image = pixmap.toImage(); QRgb rgb; ...................... ................................. if (this->isEnabled()) { if(num_of_images == 4) { painter.drawPixmap(target, pixmap, source); painter.drawText (target, Qt::AlignCenter , tr(button_txt)); } else { qDebug()<<this; if(!this->m_pressed) { qDebug()<<"not this->m_pressed paint event"; source = QRectF(0.0, 0.0, button_width, button_height); } painter.drawPixmap(target, pixmap, source); painter.drawText (target, Qt::AlignCenter , button_txt); qDebug()<<m_hovered; if (m_hovered) { qDebug()<<"m_hovered paint event"; source = QRectF(0.0, 0.0, button_width, button_height); painter.drawPixmap(target, pixmap, source); source = QRectF(button_width, 0.0, button_width, button_height); painter.drawPixmap(target, pixmap, source); //source = QRectF(0.0, 0.0, button_width, button_height); //painter.drawPixmap(target, pixmap, source); painter.drawText (target, Qt::AlignCenter , tr(button_txt)); } } painter.drawPixmap(target, pixmap, source); painter.drawText (target, Qt::AlignCenter , tr(button_txt)); } break; case 2: @ here actually i am getting a unexpected output when i am stopping a timer of button2 from button1 by QObject::connect(button1, SIGNAL(clicked()),button2,SLOT(animate_button())); when the timer stop the value of m_pressed and m_hovered in draw_button_normal() button is false and false but after this when repaint is called the value of m_pressed and m_hovered is changing to false and true. I am not able to detect why this value changed in paint event even if i am not changing.
  • Switching beween Application

    3
    0 Votes
    3 Posts
    2k Views
    F
    Seems to me a problem related to the specific platform you are running on. I think the problem is that QProcess does not know if your process runs within an x server or a command line or in background. Therefore I guess it has not effective way to place the window on top, and I think this could also be complicated by having applications running on multiple desktops. Not sure if "desktop widget":http://doc.qt.nokia.com/4.7/qapplication.html#desktop can help in this case.
  • 0 Votes
    7 Posts
    4k Views
    G
    [quote author="victor.e" date="1317852440"]So, just to confirm my understanding of how this works: even though the text editor and button controls are constructed using their default constructors (in which the parent pointer is null), adding these 2 controls to the layout object and then using this layout in the main window sets the main window to be the parent of the 2 controls?[/quote] Adding a widget to a layout implies reparenting them. This is to ensure lifetime and object deletion. Only top level QObjects (which have no parent and will not be part of layouts etc) should be created on the stack, all other should be on the heap. There are some special cases where children on the stack would work, but I would never use those.
  • QComboBox > QListView

    5
    0 Votes
    5 Posts
    4k Views
    R
    I've solved so... @ QDir dir; dir.setPath (ListDir); for (int i=0;i<dir.entryList(QStringList("")).count();i++){ QString fileName = dir.entryList(QStringList("")).at(i); ui->listWidget->addItem(fileName); } @ thanks... [EDIT: code formatting, please wrap in @-tags, Volker]
  • SVG Format Images in Qt

    2
    0 Votes
    2 Posts
    2k Views
    V
    Look to [[Doc:QtSvg]] module.
  • [SOLVED] help with layout

    6
    0 Votes
    6 Posts
    3k Views
    F
    I managed it in the end! The problem was in the constructor of the UserView, that while it was setting up a layout, it was not adding widgets to it. The final code that works is therefore: @// set up a vertical layout QVBoxLayout* vLayoutMain = new QVBoxLayout( this ); setLayout( vLayoutMain ); setUpPanelMaster(); vLayoutMain->addWidget( panelMaster ); @ and now it is displayed correctly.
  • Custom cursor does not change on Mac

    5
    0 Votes
    5 Posts
    3k Views
    I
    Irfan Omair : did you find something to help me on Mac? sorry to bother you but honestly speaking I could not figure out how to do it on Mac/Cocoa
  • "Special Items" in QMenu

    6
    0 Votes
    6 Posts
    9k Views
    S
    Finally got around to implementing this using the two QMenu approach. Took awhile because a lot of the QMenu code is pretty complex and many functions aren't directly exposed in the QMenu API. The idea was pretty simple, but I had to go back and add a bunch of overrides for little things like when the mouse enters one of the internal QMenus and doesn't dehighlight any of the other actions (or vice versa). And it's pretty easy to connect to the main QMenu, so triggering the option box can emit the action from the outer menu just as the submenu does. @ import sys from PyQt4.QtCore import * from PyQt4.QtGui import * class OptionBoxAction(QWidgetAction): class InWidgetMenu(QMenu): def enterEvent(self, event): # unhighlight neigboring actions (shouldn't this be built in?) # super(OptionBoxAction.InWidgetMenu, self).enterEvent(event) self.parent().parent().setActiveAction(None) def leaveEvent(self, event): super(OptionBoxAction.InWidgetMenu, self).leaveEvent(event) self.update() def mouseMoveEvent(self, event): super(OptionBoxAction.InWidgetMenu, self).mouseMoveEvent(event) self.update() class MainMenu(InWidgetMenu): def paintEvent(self, event): p = QPainter(self) action = self.actions()[0] # should only have one action rect = QRect(self.actionGeometry(action)) rect.setWidth(self.width()) # QActions don't automatically resize opt = QStyleOptionMenuItem() self.initStyleOption(opt, action) self.style().drawControl(QStyle.CE_MenuItem, opt, p) class CustomMenu(InWidgetMenu): def paintEvent(self, event): p = QPainter(self) action = self.actions()[0] # should only have one action rect = QRect(self.actionGeometry(action)) opt = QStyleOptionMenuItem() self.initStyleOption(opt, action) opt.text = '' # only show icon opt.icon = QIcon('./optionBox.png') self.style().drawControl(QStyle.CE_MenuItem, opt, p, self) def __init__(self, *args, **kwargs): super(OptionBoxAction, self).__init__(*args, **kwargs) self._widget = QWidget() self.setDefaultWidget(self._widget) self._menuLeft = self.MainMenu() self._menuRight = self.CustomMenu() self._menuRight.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) self._menuRight.setMaximumWidth(30) self._widget.setLayout(QHBoxLayout()) self._widget.layout().addWidget(self._menuLeft) self._widget.layout().addWidget(self._menuRight) self._widget.layout().setMargin(0) self._widget.layout().setSpacing(0) def setMainAction(self, action): self._menuLeft.clear() self._menuLeft.addAction(action) self.connect(action, SIGNAL('triggered(bool)'), self.mainTrigger) def getParentMenu(self): return self._menuLeft.parent().parent() _parentMenu = property(getParentMenu) def mainTrigger(self, checked): self._parentMenu.hide() self._parentMenu.emit(SIGNAL("triggered(QAction*)"), self._menuLeft.actions()[0]) def setCustomAction(self, action): self._menuRight.clear() self._menuRight.addAction(action) self.connect(action, SIGNAL('triggered(bool)'), self.customTrigger) def customTrigger(self, checked): self._parentMenu.hide() self._parentMenu.emit(SIGNAL("triggered(QAction*)"), self._menuRight.actions()[0]) app = QApplication(sys.argv) window = QMainWindow() testMenu = QMenu("Test") add a submenu subMenu = testMenu.addMenu('Sub Menu of Options') subMenu.addAction('Option #1') subMenu.addAction('Option #2') add the action (with the option box) optionBoxAction = OptionBoxAction(testMenu) optionBoxAction.setMainAction(QAction('Test', testMenu)) optionBoxAction.setCustomAction(QAction('Never render this', testMenu)) add some other actions testMenu.addAction(optionBoxAction) testMenu.addAction('Really Long Action') testMenu.addAction('With checks').setCheckable(True) def triggerEvent(action): print('Event triggered: %s' % action.text()) wire up the QMenu (should automatically connect signal in 'optionBoxAction') QObject.connect(testMenu, SIGNAL('triggered(QAction*)'), triggerEvent) window.menuBar().addMenu(testMenu) window.show() app.exec_() @
  • No Keyboard input if QLineEdit on frameless popup window

    3
    0 Votes
    3 Posts
    3k Views
    R
    Unfortunately that doesn't work. Tried it on OSX.
  • QGLWidget in a plugin

    3
    0 Votes
    3 Posts
    2k Views
    Z
    I load plugin by clicking the button in the main window thus QApplication was already created by this moment. Just tell me if you have successfull practice in using QGLWidget in a plugin. I don't know if it is bug in my application or QGLWidget cannot really be used in a plugin. EDIT: Really, I use the class that has QGLWidget as a subclass. Tried to use QGLWidget instead. Everything ok. So the problem is in plugin.